The same code which works on VS Code, doesn't work on VS 2019 Professioonal

4 days ago 8
ARTICLE AD BOX

I have a situation which I am not sure of the root cause.

Take a look at the below code,

#include <fstream> #include <iostream> #include <string> int main() { std::string filename = R"(\\xyz\RTW\Test__TE123456789.json)"; // Create and write to the file { std::ofstream outFile(filename); if (!outFile) { std::cerr << "Error creating file: " << filename << std::endl; return 1; } outFile << "Hello, World!" << std::endl; outFile << "This is a test file." << std::endl; outFile.close(); } // Read from the file { std::ifstream inFile(filename); if (!inFile) { std::cerr << "Error opening file: " << filename << std::endl; return 1; } std::string line; while (std::getline(inFile, line)) { std::cout << line << std::endl; } inFile.close(); } return 0; }

It works when compiled with VS Code, but fails when compiled with VS 2019 professional. Here "failing" means - we return 1 while trying to create outFile. Can someone please shade some light onto this?

Thanks in advance,

Read Entire Article