I am making a school schedule, in which the user is supposed to select an exact number of subjects they are going to type in, by inputting a number, which will be stored in subCount
variable. Later on, the user is met with a loop, demanding input, where they are supposed to type in subjects one by one. The end of my program is subjects getting listed in exact order.
However, my schedule is not tied to specifically any language and for example, some of my language’s subjects’ names are divided in two words (English – Anglų kalba). I know that space works as a blank, after which all remaining contents are accordingly placed in another variable. I have tried using getline(cin, sub)
too and that did not work out.
Here is my output’s example:
Enter the subject count
6
Enter each subject one by one
(press 'Return' to move on)
Istorija
Anglų kalba
Etika
Fizika
Vokiečių kalba
------------------
Istorija
Anglų
kalba
Etika
Fizika
Vokiečių
Note that I was not let to type in another subject and "kalba" got placed separately.
Enter the subject count
6
Enter each subject one by one
(press 'Return' to move on)
Istorija
Anglų
Etika
Fizika
Vokiečių
Matematika
------------------
Istorija
Anglų
Etika
Fizika
Vokiečių
Matematika
Variation which does not use "kalba" (displayed correctly). How could I achieve what I want? My code:
int main() {
int subCount;
vector<string> subNames;
cout << "Enter the subject count\n";
cin >> subCount;
cout << "Enter each subject one by one\n";
cout << "(press 'Return' to move on)\n";
for (int i = 0; i < subCount; ++i) {
string sub;
cin >> sub;
subNames.push_back(sub);
}
cout << "------------------\n";
for (int i = 0; i < subCount; ++i) {
cout << subNames[i] << '\n';
}