Reputation: 73
My C++ program compiles and works up until I call this function from main():
int uword(){fstream infile("numbers.txt");
fstream exfile("wordlist.txt");
string numb[numoflines];
string lines[numoflines];
number = 1;
line = 1;
for(int i=0;i<numofline;++i)
{
getline (infile,number);
numb[i] = number; //I think this is causing the problem
getline (exfile,line);
lines[i] = line; //This too
}
infile.close();
exfile.close();
string yourword;
Something here causes it to crash, in the debug it pops up with "An access violation (Segmentation Fault) raised in your program."
EDIT: My mistake was using !infile.eof in the for loop.
Upvotes: 1
Views: 2119
Reputation: 72261
Not a direct answer, but I believe it's a good one...
Use The Debugger! GDB should suspend at the exact line when the segmentation fault happens, thus giving you a very good hint about what the error is.
Upvotes: 3
Reputation: 98479
The getline
function does not work the way you think it works.
Also, there could be more than numoflines
lines in infile
.
Upvotes: 1