Help with file manipulation ...

Hello everybody, I'm desperate because I don't know anything about C++ and I must organize 340 files with experimental data from my thesis (I've tried to do this with MATLAB but demands a lot of time). Now I decided to use the C++. So,I must take a *.txt file open it and modify some rows as follow:

...
44,3256 0 0 108 23,568
44,3567 211 0 0 25,045
44,4620 0 104 0 25,786
44,8795 326 154 0 26,114
...
So I've 'm' rows (at least 22500 rows) by 5 columns and I must compare and save another file which
could not have values =<108 neither zero in the three central columns that are named as SR1 SR2 and SR3 respectively. After thie I'll use a dat file as input to solve an equation in Fortran. In the sample above the rows 1 and 3 must be deleted before sava the new file. I'm not sure if the file can be read as string or binary. So anu help Will be very appreciated. Thanks in advance.
Last edited on
Im not sure what the question is??

Id use an ifstream to .open("myfile.txt")
build a stringstream around a getline on that stream,
use the getline with the comma delim to pull in each 'field'


for example if said data was in myFile.txt in same directory::


#include <fstream>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;

int main(){
string sr1,sr2,sr3;
ifstream s;
s.open("myFile.txt");
if(s.good()){
while(!s.eof()){
string temp; getline(s,temp); stringstream line(temp);
getline(s,sr1,','); getline(s,sr2,','); getline(s,sr3);
cout<<"Sr1: "<<sr1<<" Sr2: "<<sr2<<" Sr3: " <<sr3<<endl;
}

}
cout<<"***************"<<endl;
system("pause");
return 0;
}

im not sure if this helps... but may get you on track
Topic archived. No new replies allowed.