Hi,

I am trying to read values from a text file that has exactly 5 numbers in each line and all numbers are "tab" separated. numbers could be one digit or two digit.

I am reading it as :

if (map.is_open())
	{
		int i = 0;
		int num;
		while (!map.eof())
		{
			getline(map,line);
			if (line == "")
			{
				continue;
			}
			else
			{
				while (line >> map)
				{
				cout << "Line is " << line << endl;;
				int pos1 = 0;
				Graph[i].value = GetIntValue(line.substr(pos1+1,pos1+1));
				pos1 = line.find("	");
				cout << "Graph[" << i << "] = " << Graph[i].value << endl;
				i++;
//I need to make the reminder as my line now -- > this is killing me as I do not know //the length of line..
				}				
			}
		}
	}

GetIntValue is a small function that takes in a string and returns a int.
basically I need to read each line(lines are exactly 5 in number), store in an array. each line has exactly 5 numbers.

any sort of help would be really appreciated!

Looks like you are doing it the hard way

int n1,n2,n3,n4,n5;

while( map >> n1 >> n2 >> n3 >>n4 >> n5 )
{
   // do something with these numbers
}
int val_arr[5][5];
int i=0;
while (file)
    {
      string str;
      int j=0;
      while (getline( file, str, '\t' )) 
        var_array[i][j++] = ( atoi(str) );
      i++;
    }

//User val_array[][]
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.