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:
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