reading data from text files when given a specific line

hello, i am currently making a game where data is saved and loaded. i have used fstream to read and write the files. i am having trouble getting an integer value when given a specific line to read.
this is my current code for getting the value:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
int getValueInteger ( int line )
{
	int currentLine = 0;
	string fileLine;
	int length = 0;
	int number = 0;
	int arrayNum = 0;
	
	file.clear ( ) ;
	file.seekg ( 0, ios::beg );
	
	while ( !file.eof ( ) )
	{
		currentLine++;
		getline(file, fileLine);

		if (currentLine == line)
		{
			length = fileLine.size ( );

			for ( int i = 1; i < length + 1; i++ )
			{
				char character = fileLine[i];

				if ( character >= '0' && character <= '9')
				{
					number *= 10;
					number += fileLine[i];	
				}
			}
			break;
			
		}
	}
	
	return number;
}


im not sure if the error is with number[] getting a value or with the value of numberGiven.
the text file is:
1
2
ResolutionX: 1080
ResolutionY: 720


where line = 1 to find 1080 but it returns 544080

what is wrong with the code and how can it be fixed
thanks in advance
Last edited on
Topic archived. No new replies allowed.