Any other way than using ofstream to write data to .txt files in C++ [closed]

StackOverflow https://stackoverflow.com/questions/14316327

  •  15-01-2022
  •  | 
  •  

문제

I tried to use ofstream to write data to a .txt file in OMNET++ as follows with iostream and fstream included:

ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();

But OMNET++ is not resolving open and close functions.

Can someone suggest any way other than ofstream to achieve the same task of reading and writing data to .txt files in C++?

도움이 되었습니까?

해결책

Turning my comment into an answer.

ofstream (and all other Standard Library classes) are defined in namespace std. You need to use qualified names (such as std::ofstream) to access them.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top