Monday, 19 August 2013

Detect new line c++ fstream

Detect new line c++ fstream

How do I read a .txt copy the content to another .txt by using fstream to
get exactly the same content. The problem is, when in the file there is
new line. How do I detect that while using ifstream?
Eg: note.txt => I bought an apple yesterday. It tastes delicious.
note_new.txt => I bought an apple yesterday. It tastes delicious. // the
second sentence suppose to be in the next line.
Here is my current code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inFile ("note.txt");
string word;
ofstream outFile("note_new.txt");
while(inFile >> word) {
outfile << word << " ";
}
}
can you all help me? actually I also check when the word retrieved is the
same as what user specified, then I won't write that word in the new file.
So it general, it will delete words which are the same as the one
specified by user.

No comments:

Post a Comment