K
krista
Hi,
I am beginner of C++. When I try to read a file and put it into X and
Y variables. I got that segmentation fault.
the data file is
data.txt:
4.4 6.8
3.2 -5.5
3.3 0.9
I just want to print out the file as target: 4.4,6.8
target: 3.2,
-5.5........
I already can read the file
but i cannot separate the data in a line from the file to x and y
variables
the code is
ifstream in;
in.open(data.txt);
char str[100];
while (!in.eof()){
in>>str;
double X=atof(strtok(str," ");
double Y=atof(strtok(NULL," ");
cout<<"Target:"<< X << " "<< Y <<endl;
}
then the result is segmentation fault.
Please advise.
Krista
I am beginner of C++. When I try to read a file and put it into X and
Y variables. I got that segmentation fault.
the data file is
data.txt:
4.4 6.8
3.2 -5.5
3.3 0.9
I just want to print out the file as target: 4.4,6.8
target: 3.2,
-5.5........
I already can read the file
but i cannot separate the data in a line from the file to x and y
variables
the code is
ifstream in;
in.open(data.txt);
char str[100];
while (!in.eof()){
in>>str;
double X=atof(strtok(str," ");
double Y=atof(strtok(NULL," ");
cout<<"Target:"<< X << " "<< Y <<endl;
}
then the result is segmentation fault.
Please advise.
Krista