Dear All,

I'm writing a code which could read the following file:
(input.raw) contained:
11 12 13
21 22 23
31 32 33

While reading this file I want to do the following:
-Move cursor to the beginning of that file which is before "11", then start reading
-After reading 11 the ' ' will read in too, in this step I want to skip reading this line by moving the cursor to the beginning of next line which is before "21", then again skip reading this line when ' ' is found, move cursor to the beginning of next line which is before '31'.

Please help me I'm getting stuck in here.

Thanks in advance.

10 Years
Discussion Span
Last Post by Duoas

Use a stringstream to get stuff out of a string.

#include <fstream>
#include <sstream>
#include <string>

ifstream inf( "fooey.txt" );
string line;
while (getline( inf, line ))
  // if the line is blank, ignore it
  if (line.find_first_not_of( " \t" ) == line.end()) continue;
  // get the first integer off the line
  stringstream linestream( line );
  int n;
  if (!(linestream >> n))
    dosomething( n );

This gets one line at a time from the file, and endeavors to get the first item on the line (if any) as an integer number.

Hope this helps.

[edit] hmm... I'm slow...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.