L
las
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
int main()
{
string token1 = "Hello\nall";
fstream newfile("C:/temp/test1.txt", ios::trunc);
if ( newfile.good() )
{
cout << token1.c_str() << endl << "Size of string is " <<
token1.length() << endl;
newfile.write( token1.c_str(), token1.length() );
newfile.flush();
}
else
{
cout << "Error with newfile" << endl;
}
file.close();
system("PAUSE");
return 0;
}
Why doesnt the above code write the token1 string to the test1.txt file ?
#include <fstream>
#include <stdlib.h>
#include <string>
int main()
{
string token1 = "Hello\nall";
fstream newfile("C:/temp/test1.txt", ios::trunc);
if ( newfile.good() )
{
cout << token1.c_str() << endl << "Size of string is " <<
token1.length() << endl;
newfile.write( token1.c_str(), token1.length() );
newfile.flush();
}
else
{
cout << "Error with newfile" << endl;
}
file.close();
system("PAUSE");
return 0;
}
Why doesnt the above code write the token1 string to the test1.txt file ?