1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include<vector>
int main(){
vector<float> M;
string line;
ifstream myfile ("data.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
float s=atof(line.c_str());
M.push_back(s);
//cout << line << endl;
}
//cout<<M[M.size()-2];
myfile.close();
}
else cout << "Unable to open file";
//cout<< M.size();
for (int y=0;y<=M.size();++y){
cout<< M[y]<<endl;}
return 0;
} |
Partager