Original Post
Hey,
I need to load paths to particular sounds from txt file and pass those paths to vector of LPCSTR type. Therefore I have some questions about the code I've made:
This code doesn't work... I have no certain idea why but out of while loop every waveFile element has the same path (the last one loaded from txt)...
I came up with a solution:
Now all the elements of waveFile vector have proper values.
Does anyone know why my first code didn't work? I honestly do not know what even might be wrong... I would be evry grateful for any help!
I need to load paths to particular sounds from txt file and pass those paths to vector of LPCSTR type. Therefore I have some questions about the code I've made:
std::vector <LPCSTR> waveFile;
std::fstream file( "data/sounds.txt", std::ios::in );
char line[255];
while( !file.eof() )
{
file.getline( line, 255, ' ' );
file.getline( line, 255, '\n' );
waveFile.push_back(line);
}
file.close();This code doesn't work... I have no certain idea why but out of while loop every waveFile element has the same path (the last one loaded from txt)...
I came up with a solution:
std::vector <LPCSTR> waveFile;
std::fstream file( "data/sounds.txt", std::ios::in );
char line[20][255];
int a = 0;
while( !file.eof() )
{
file.getline( line[a], 255, ' ' );
file.getline( line[a], 255, '\n' );
waveFile.push_back(line[a]);
a++;
}
file.close();Now all the elements of waveFile vector have proper values.
Does anyone know why my first code didn't work? I honestly do not know what even might be wrong... I would be evry grateful for any help!