0

How to declare a array of string and how to call it in the cin

Cpp

20th Dec 2019, 11:54 AM
Waleed Ahmad
Waleed Ahmad - avatar
6 Answers
+ 2
How about writing a simple menu then? You can use an integer to represent the different choices the user has, and you could also choose to put everything inside a loop to let the user enter strings repeatedly until he decides to stop. It could look like the following (the code is just a bare skeleton example though): https://code.sololearn.com/cmk076e7ue3B/?ref=app If you have an array of strings instead of multiple variables, you can use the integer as index to refer to the different strings when acquiring the input.
20th Dec 2019, 12:13 PM
Shadow
Shadow - avatar
+ 3
Not sure if this is what you mean, but you can declare an array of strings just like any other array, e.g. string arr[ 5 ]; And then you can request single strings from the user by referring to the string located at a certain index: cin >> arr[ 0 ];
20th Dec 2019, 11:58 AM
Shadow
Shadow - avatar
+ 1
Ur amazing thx
20th Dec 2019, 12:15 PM
Waleed Ahmad
Waleed Ahmad - avatar
0
I have 3 strings private and governmental and international and the user should choose the one of them How can i put in the cin
20th Dec 2019, 12:01 PM
Waleed Ahmad
Waleed Ahmad - avatar
0
So you want to let the user choose which string to enter?
20th Dec 2019, 12:03 PM
Shadow
Shadow - avatar
0
Exactly
20th Dec 2019, 12:04 PM
Waleed Ahmad
Waleed Ahmad - avatar