+ 1

How can I input string from user in a vector ???

15th Oct 2017, 6:53 PM
Raana Yavari
Raana Yavari - avatar
4 Respuestas
+ 5
@Naitomea I don't think you need a vector of strings here. Why store single characters in an entire string? I think you should use char instead, and it will work the same.
16th Oct 2017, 1:28 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
I think I would do it this way: std::string s = ""; //Your string std::cin >> s; //Get user input std::vector<std::string> whatever; //Vector of strings whatever.push_back(s); //push_back appends the given value s to the end of the vector
15th Oct 2017, 7:11 PM
Shadow
Shadow - avatar
+ 1
@Kinshuk Sure, thats right, I just based it on the opportunity to have multiple user inputs and therefore multiple strings, then a vector of strings would make sense, wouldnt it? If not, feel free to correct me :)
16th Oct 2017, 5:54 AM
Shadow
Shadow - avatar
- 1
شاید
18th Oct 2018, 10:19 PM
hossein Soltanian
hossein Soltanian - avatar