Hi everyone! I am having issues with how to terminate an input stream with a specific pre-defined string instead of a generic Ctrl+Z. Here is my code (INCOMPLETE!):
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <complex>
#include <ctime>
usingnamespace std;
int main()
{
cout << "Please type a person's name and his/her score." << endl;
string name;
int score;
int x = 0;
vector<string>names;
vector<int>scores;
// How should I terminate the input stream below with a "No more" string instead of a generic Ctrl+Z ? Thank you!
while(cin >> name >> score)
{
for(int i = 0; i <=x; i++)
{
if(name == names[i])
{
cout << "Sorry. The name: " << name << " is entered twice." << endl;
cout << "Please type a person's name and his/her score." << endl;
}
else{
names.push_back(name);
scores.push_back(score);
cout << "Please type a person's name and his/her score." << endl;
x++;}
}
}
cout << "Program terminated by user." << endl;
for(int y = 0; y <= x; y++)
{
cout << names[y] << " --- " << scores[y] << endl;
}
}
Can anyone show me how should I accomplish this? Thank you very much!
Hi chipp! Sorry about the mistake. I changed the v into names. Thank you.
Hi Phil123, I am a beginner in C++ so I didn't learn about the getline() function yet. Do you see any other way I could do this on the basis of my code? Thank you!