Hello guys,
I have a problem in reading a set of numbers from a text file.
The text is as follows
2 3000
P 500 20 200 L(3) 300 U(3) 400
A 2 10 500
I need to read the data character by character and use them. The input txt data can change and it may have more lines than one given above.
[/code]
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string line[3];
int i;
ifstream myfile("data.txt");
if (myfile.is_open())
{
for (i = 0;i < 3;i++)
{
while ( getline (myfile,line[i]) )
{
cout << line [i]<< '\n';
}
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
[code]
Now my output is as follows.
line[0] = 2 3000
line[1] = P 500 20 200 L(3) 300 U(3) 400
line[2]= A 2 10 500
i need to know how to get each character separately?