Question

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++?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top