Is there a way to have user input multiple char arrays at once c++ -
i have function takes array of 4 characters , returns value based on sequence of characters.
what want have user input whole line of characters , create loop go on each "sub- group of characters" , return result of them.
my initial thinking somehow use push_back keep adding arrays vector.
i don't know how long entire array be, should product of 3.
as example, right able :
char input [4] ; cin >> input; int = name_index[name_number(input)]; cout << name[i].fullname;
but user ti input multiple name abbreviations @ once
i change sample this:
char input [4] ; cin >> input; int = name_index[name_number(input)]; cout << name[i].fullname;
to this:
string input; cin >> input; const int = name_index[name_number(input)]; cout << name[i].fullname;
then can start using vector track multiple inputs:
vector<string> inputs; string line; while (cin >> line) { if (line == "done") break; inputs.push_back(line); } (unsigned int = 0; < inputs.size(); ++i) { cout << "inputs[" << << "]: " << inputs[i] << endl; //const int index = name_index[name_number(inputs[i])]; //cout << name[index].fullname; }
you asked explanation of line
. line while (cin >> line)
tries take text standard input , put line
. default, stop when encounters whitespace (space, tab, return, etc.) if succeeds, body of while
loop executed , add input vector
. if not, assume we're @ end of input , stop. can process vector
. (in code linked below, output since don't know name_index
or name_number
are.
Comments
Post a Comment