数据如:
0.000 20.84
1.000 24.95
2.000 33.20
3.000 40.55
4.000 48.65
5.000 55.50
6.000 60.50
7.000 66.50
8.000 74.60
9.000 85.10
10.000 95.55
12.000 98.65
13.000 102.25
14.000 103.25
15.000 104.25
16.000 105.25
17.000 107.25
18.000 108.25
19.000 107.15
20.000 105.65
21.000 103.95
22.000 104.25
23.000 104.95
24.000 104.35
25.000 104.15
26.000 103.65
27.000 103.95
28.000 103.15
29.000 102.55
30.000 99.45
31.000 97.85
32.000 95.25
c版本
vector<int> vFirstData; vector<float> vSeconndData; FILE *pf = fopen("Test.txt","r"); if (pf == 0) return; while (!foef(pf)) { int nNum; float fData; fscanf("%d %f", &nNum, &fData); vFirstData.pushback(nNum); vSecondData.pushback(fData); }
c++版本
double temp; vector <double> vector1; vector <double> vector2; ifstream infile("test.txt",std::ios::in); while(infile> > temp) { vector1.push_back(temp); infile> > temp; vector2.push_back(temp); } infile.close(); 这里使用的是标准的输入输出流。空格的问题标准库解决了。 空格