I have written a code, and in the beginning of it, it should get input from command line and put them in vectors. That part of my code is:
1 2 3 4 5 6 7 8 9 10 11 12 13
while(cin>>name>>surname>>id>>by){ // takes the inputs
// pushes the values into the vectors
namevect.push_back(name);
surnamevect.push_back(surname);
idpvect.push_back(id);
bypvect.push_back(by);
}
But when I press Ctrl-D it gives a segmentation fault error. It has nothing to do with the vectors (I think), because I tried them all and printed out the contents and it was alright. Nothing happens when I'm in while loop, segmentation fault happens when I go out of the loop.
I could not find a solution. Any ideas?
string name, surname, id, by;
vector <string> namevect; // vector for names
vector <string> surnamevect; // vector for surnames
vector <string> idpvect; // vector for id's
vector <string> bypvect; // vector for birth years
while(cin>>name>>surname>>id>>by){ // takes the inputs
// pushes the values into the vectors
namevect.push_back(name);
surnamevect.push_back(surname);
idpvect.push_back(id);
bypvect.push_back(by);
// I also tried to print out the contents of the vectors here, it prints them all right.
}
// when I put a printing statement here, out of the loop, it does not get printed
The problem is, as I said, when the loop terminates :/
@firedraco , g++
I give inputs to this program from the command line. It is supposed to push them in 4 seperate vectors, and does that, too. (I can print them in the loop). But when I press Ctrl-D in order to go out of the while loop, it gives segmentation fault error. And dos not even go through the statement after the loop. So there is something wrong there with the while loop, but could not see why.
p.s. I use g++ that comes with the centos linux distribution, on a virtual machine.
by the way, it compiles, but gives this error while running