Hello everybody, I´m reading a text file with words, and something strange happens.
Suppose that I´m reading the following words (this words are in the text file):
cebolla
yuca
When I opened this words with the getline method that is in the stream class, I got this:
cebolla
yucalla
As you can see, the word yuca take the last tree letter of the word cebolla. Someone knows why this is happening? I guess that I did not flush the stream.
I don't know if I understand the problem. After calling getline(), lista should contain some characters followed by a null character ('\0'). I can only give you a general advice:
Instead of this:
1 2
char lista[longitud];
while (elArchivo.getline(lista, longitud))
try this:
1 2
std::string lista;
while (std::getline(elArchivo, lista))
And do the same everywhere you're using char[] or char*. Replace it with std::string.