-
whats wrong?
All im tryin to do is convert a text file with a list of words to the ascii equivalent. but I always get an error, "Expression: string subscript out of range". Any help would be appriciated.
int main ( )
{
ifstream fin;
fin.open ( "wordlist.txt" );
string line;
int x = 0;
while ( getline ( fin, line ) )
{
while ( x != sizeof ( line ) )
{
cout << int (line[x]);
x++;
}
cout << '\n';
}
return 0;
}
-
Re: whats wrong?
Instead of sizeof(line), use line.size().
Also, don't forget to reset x to 0 after each run of the inner loop. It might be better to use < instead of != because that would have caught this problem.
-
Re: whats wrong?
thz jlou, i forgot about reset x to 0. So dumb of me to have missed that great thz jlou.