I am attempting to take names and weights from strings and just simply output them. For some reason it can't get out of the while loop, it just sets there waiting for the users to input names and weights. Here's my code
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main (void)
{
// creating variables for input
string name;
int weight;
// creating vectors
vector<string> names;
vector<int> weights;
cout << "Enter names and weight" << endl;
while(cin >> name, weight)
{
names.push_back(name);
weights.push_back(weight);
}
// outputs names and weight
for( unsigned int n = 0; n < weights.size(); n++ )
{
cout << "[" << n << "] " << weights[n] << " " << names[n] << endl;
}
cout << "done." << endl;
return 0;
}
I am self teaching myself C++ with someone helping me as well, my issue is. I am currently learning from Accelerated C++ book. I am on chapter three.
The problem is it doesn't come out of the while loop. It doesn't know when the user will stop input. How do I do it this way, but make it so the computer knows when the while(cin >> ) stops from the user input.