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