M
mov
I am a newbie, please someone tell me how to create a text file and save it
using c++.
thanks
using c++.
thanks
mov said:I am a newbie, please someone tell me how to create a text file and save it
using c++.
Victor said:#include <fstream>
int main()
{
std:fstream os("text_file.txt");
Aggro said:// Check could we open file for writing or not
if( os )
{
os << "Hello world!";
}
else
{
// This could happen for example if file already exists
// and it is read-only or user doesn't have permission to write
// into it.
std::cout << "Failed to open file";
Victor said:Create an std:fstream object. Write to it using <<.
#include <fstream>
int main()
{
std:fstream os("text_file.txt");
os << "Hello world!";
}
V
Isn't it important to close the file after writing it ?
os.close(); ?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.