I am trying to to read each line from a text file and put in array column ,I really tried this :
string buffer[256];
string a;
ifstream myfile ("1.txt");
for(i=0;i<10000;i++)
{
//readArrivalTimes(i);
myfile.getline (buffer,100);
a[i]=buffer;
}
but It is not working
so I did try for one of the solutions you gave me guys and I did it like this :
std::vector<std::string> v;
std::string buffer;
string a[1024];
ifstream myfile;
myfile.open("1.txt");
for(i=0;i<n;i++)
{
getline (myfile, buffer);
a[i]= buffer;
cout << buffer << "\n";
}
but as we can see it's string !
can we make it works as integer?
[Solved :)]
first of all thanks for everybody help me with this, I really appreciate your help, I am a totally new to c++.
and for sure it's not a homework.
I did some modifications to the code so it can works with integers
int a[1024];
ifstream myfile;
myfile.open("1.txt");
for(i=0;i<n;i++)
{
getline (myfile, buffer);
a[i]= atoi(buffer.c_str());
cout << buffer << "\n";
}
thank you very much.