I'm trying to write a program to extract words from a text file and store them as strings in a vector of type string. When I try to execute it, the program hangs indefinitely. There are no visible syntax errors, and I have no idea what's wrong.
Any help would be appreciated. Here's The code:
Code tags and indentation are prerequisites to help in the vast majority of cases.
Also, you know that stdafx is not necessary in that case right? stdafx is just an MSFT precomp'd header for the ones people use a lot.
OK, let's see... perhaps you should close infile after you are finished with it, rather than after.... Well I don't really understand the nesting on that second loop. You can streamline that to, in pseudocode (at least I think this should work)
1 2 3 4 5 6
while (get a string from infile)
{
add the string to your vector
} // at this point you've extracted everything you can already
// so only now should you close it with
infile.close();
OK, so that was quasipseudocode. But you see what I mean, right? When infile reaches the EOF, the test will be unsuccessful (the while infile >> str) and then you can close it. You can check this for more data, and because I am probably wrong: http://www.cplusplus.com/doc/tutorial/files/