I/O file stream C++ -
#include <iostream> #include <string> #include <cstring> #include <fstream> using namespace std; int main() { string temp; ifstream infile; ofstream outfile; infile.open("zrmk matched - 010513.txt"); outfile.open("second.txt"); while(!infile.eof()) { getline(infile, temp); if (temp != "") { getline(infile, temp); outfile << temp; } } cout << "data transfer finished" << endl; homecoming 0; }
i'm having difficulty getting work. when execute programme cycles awhile , terminates without finishing -- doesn't output lines of text output file. help appreciated.
are trying re-create every line?
while(std::getline(infile, temp)) { outfile << temp << "\n"; }
are trying re-create every non-blank line?
while(std::getline(infile, temp)) { if(temp != "") outfile << temp << "\n"; }
are trying re-create every 2nd non-blank line?
int count = 0; while(std::getline(infile, temp)) { if(temp == "") continue; count++; if(count % 2) outfile << temp << "\n"; }
are trying re-create entire file?
outfile << infile.rdbuf();
c++
No comments:
Post a Comment