Code: Select all
std::fstream *fs = NULL;
fs = new std::fstream();
fs->open("D:/Projects/Test_project/Release/test.txt");
if(!fs)
cout << "\nUnable to Open";
*fs << "Put this text in file";
fs->close();
Code: Select all
std::fstream *fs = NULL;
fs = new std::fstream();
fs->open("D:/Projects/Test_project/Release/test.txt");
if(!fs)
cout << "\nUnable to Open";
*fs << "Put this text in file";
fs->close();
Better use something like thisAbsoluteCPP wrote:why this code not work, (it compiles successfully) but create no txt file as a output.Code: Select all
std::fstream *fs = NULL; fs = new std::fstream(); fs->open("D:/Projects/Test_project/Release/test.txt"); if(!fs) cout << "\nUnable to Open"; *fs << "Put this text in file"; fs->close();
Code: Select all
std::ofstream file("file.txt", std::ios::out);
if (file.good())
{
file << "Put this text in file\n";
}
else
{
//Error handling here
}
file.close();