How to output STL string into a file
-
How to output string into a file? My part of code is belowLook at the last line, it is not ok.) // Open the file ready write if((pOutputFileStream = fopen(csFilePath, "w")) != NULL) bStatus = TRUE; // Otherwise output message to the console window. else { printf("The output %s file is not available!", csFilePath); bStatus = FALSE; } if (bStatus) { // STL string. string str = vNode.back (); cout << str << endl; // // this line is not ok. // fprintf(pOutputFileStream, "%s", str.substr); } Thanks. mIchAel Liu __________________________________________________________ The secret of business is to know something that nobody else knows. ;)
-
How to output string into a file? My part of code is belowLook at the last line, it is not ok.) // Open the file ready write if((pOutputFileStream = fopen(csFilePath, "w")) != NULL) bStatus = TRUE; // Otherwise output message to the console window. else { printf("The output %s file is not available!", csFilePath); bStatus = FALSE; } if (bStatus) { // STL string. string str = vNode.back (); cout << str << endl; // // this line is not ok. // fprintf(pOutputFileStream, "%s", str.substr); } Thanks. mIchAel Liu __________________________________________________________ The secret of business is to know something that nobody else knows. ;)
You're using C++ to output to the console, and C to output to the file. Use iostreams instead. #include <iostream> #include <fstream> #include <string> using std::string; using std::ofstream; ... string s("This is a test of the veracity of my system"); ofstream op("c:\\test.txt"); op << s; // can call op.close(), but the destructor does it anyhow. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002