Chat on IRC |
i can't execute only one line.... fout2 << x; plz hlp
Posted by matheo917 [send private reply] at August 31, 2001, 07:04:33 PM
i am including short program i just need someone to look over it
the only problem is that the line .... fout2 << x; .... doesn't execute. ... everything else works fine, even the program compiles links with no problem please post only a short answer pertaing to that only line or e-mail me at matheo917@home.com #include <fstream> #include <string> using namespace std; //----------------------------------------------------- void Printing(string letters) { ofstream fout2("c:\My Documents\char.txt", ios::app); if (fout2) { string x = letters; fout2<< x; // it only doesn't want to write this to the file // everything is o.k. up to this point } else cout << "char.txt never got opened for output"; fout2.close(); } int main() { //------------------------------------------------------ ofstream fout("c:/My Documents/temp.txt"); int i = 0; cout << "Please enter 20 characters: \n"; do { char character[21]; cin >> character[i]; fout << character[i]; i = i + 1; }while(i < 20); fout.close(); //-------------------------------------------------------- ifstream fin("c:/My Documents/temp.txt"); string letters; int j; while (!fin.eof()) { getline(fin, letters, '\n\); } Printing(letters); fin.close(); //-------------------------------------------------------- return 0; }
Posted by Psion [send private reply] at September 01, 2001, 08:10:54 PM
Try flushing the file stream to make sure it isn't waiting for an "enter" to be printed before saving a line.
Register as a new user | ||||