Working on a project for a class, where I need to take a number in from the user and perform a task depending on the number. Read in a graph from the command line before taking in the number. The issue is that the cin>> is skipped and doesnt allow the user to enter a number. Ive tried putting cin.clear() and cin.ignore() in a few different places but it didnt seem to help. Included is the relevant code
EDIT: For clarification Im inputting a graph when I run the program like so: ./streets > bel.osm.graph. The code outputs "Enter your number: " and then ends before you can input a number.
int main(int argc, char *argv[])
{
string input;
int colct;
sparseMat graph;
readMat(graph, colct);
cout << "Enter your number: ";
cin >> input; //is being skipped
if(input == "1"){
cout << "n= " << graph[0][0].getVal() << "; m= " << graph[0][1].getVal() << ".\n";
}
}
void readMat(sparseMat& graph, int& colct)
{
colct = 0;
string line;
while (getline(cin, line)) // get next full line of text; NB: text
{
istringstream lstream(line);
sparseRow neighbours;
nz next;
while (lstream>> next) { // peel off values in this line, one at a time
neighbours.push_back(next);
}
graph.push_back(neighbours);
}
cin.clear();
}