- #1
ChrisVer
Gold Member
- 3,378
- 464
I know this is pretty basic question, but something doesn't seem to work right for me...
Suppose I have a txt file, with the following input:
How can I pass those numbers into x and y arrays using a C++ code?
My code so far is like this:
But it seems that the 2nd loop doesn't put my values for x,y's into the corresponding arrays. The filled elements are extremely small numbers which I didn't even input.
Any feedback?
Suppose I have a txt file, with the following input:
Code:
x y
0.0 0.5
1.0 1.5
2.0 4.8
3.0 4.9
My code so far is like this:
C:
#include<iostream>
#include<fstream>
using namespace std;
int main(){
//read file
ifstream finput;
finput.open("data.txt");
// part to calculate the dimensionality
int N=0;
double temp;
while(! finput.eof() ){
finput >>tempp;
N++;
}
N=N/2;//part to fill the arrays
double x[N];
double y[N];
int m=0;
while(! finput.eof() ){
finput >>x[m]>> y[m];
m++;
}
system("pause");
return 0;
}
But it seems that the 2nd loop doesn't put my values for x,y's into the corresponding arrays. The filled elements are extremely small numbers which I didn't even input.
Any feedback?