I have a s1.txt like this :
3,R,G,T
1,E
9,T,U,Y,O
Now I want to read each character of a each line ...do some analysis and then read each character of the next line ...do some analysis ...so on till EOF.
How do I go abt this?
Well ...I jus wrote a simple program to read a file as below:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main() {
//char sum = 0;
char x;
ifstream inFile("s1.txt");
if (!inFile) {
cout << "Unable to open file";
exit(1);
}
while (x != '\n') {
while (inFile >> x) {
cout<<"x = "<<x<<endl;
}
}
inFile.close();
getchar();
return 0;
}
Doing the above ...I get the entire file as output ... why is'nt it stopping execution as soon as it hits a newline as I mentioned in the first while loop? After I get the first line ...how do I parse through it to analyse each character in the line?