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.

After reading the number you need to flush the remainder of the line. Read this Read Me thread to see how to do that.

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))
    that_was_not_an_integer();
  else 
    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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.