Right, that makes things easier . . . this works for me:
Code:
#include <sstream>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main() {
ifstream infile("in.txt");
ofstream outfile("out.txt");
string mystring;
char name[80], password[80];
int number;
char comma1, comma2;
while(getline(infile, mystring)) {
istringstream ss(mystring);
if(ss >> number >> comma1 >> name >> comma2 >> password
&& comma1 == ',' && comma2 == ',') {
outfile << number + 100000 << " , " << name << " , " << password
<< endl;
}
else {
clog << "Error processing line: " << mystring << endl;
}
}
outfile.close();
infile.close();
return 0;
}
The output is
Code:
$ cat in.txt
1 , john , pass
2 , sam , word
$ ./test2
$ cat out.txt
100001 , john , pass
100002 , sam , word
$