int main ()
{
string str; // Set up string str
string str2, str3; // Subdivide str
ifstream myfile ("c:\\bust\\bust_samples\\mattias_s.txt");// Get file input
if (myfile.is_open())
{
while (! myfile.eof() )// Read to end of file
{
getline (myfile, str);// Get each line from myfile and put it in str
str2 = str.substr (7, 8); // str2 = value @ 7 in for 8 characters
str3 = str.substr (18, 8); // str3 = value @ 18 in for 8 characters
// Output to screen is = 111.6001 228.5585
//
// 106.0332 234.7669
// 110.2210 232.1646
// 111.6001 230.2080
// 111.6001 228.5585
// This is what I want all the values from the stream.
// How can I get this output ? string array ?
The cout which preform the output is located outside the loop which gets lines from the file. So you will only print the last line which was read from the file.
1 2 3 4 5 6 7 8
while (! myfile.eof() )// Read to end of file
{
getline (myfile, str);// Get each line from myfile and put it in str
str2 = str.substr (7, 8); // str2 = value @ 7 in for 8 characters
str3 = str.substr (18, 8); // str3 = value @ 18 in for 8 characters
cout << str2 << ' ' << str3 <<"\n";// output to screen
}
It would probably work correctly if the cout line was located in the loop =)