I amin the process of writing a program that takes and input string and stores each character into a vector element. My problem is though how can i tell then the user has entered all of there text? right now i just said end with '*' and put that in the while loop condition.
#include<iostream>
#include<vector>
usingnamespace std;
vector<char> GetInput ();
int main (){
vector<char> test;
test = GetInput();
for(int i=0;i<the.size();i++){
cout << test[i] << endl;
}
return 0;
}
vector<char> GetInput (){
vector<char> InputString;
cout << "Please input the string of symbol you would like to gain all permutations of: ";
char temp = 0 ;
while( temp != '*' ){ // here is my issue what should i put for the while loop condition?
cin >> temp;
InputString.push_back(temp);
}
return InputString;
}
Using cin >> temp; will skip all the spaces entered so its better to use cin.get(temp);
cin is unlikely to provide any of the characters to the program until the user pressess the return key. Then the program will get everything typed all at once. So, the return code that is inserted into the input is the natural way to terminate your input: