+ 3
Can anybody tell how to get input from user in vector of string in c++?
question about vector .
17 Answers
+ 11
is this what you are looking for?
https://code.sololearn.com/cANf9UlPmEGM/?ref=app
+ 9
https://code.sololearn.com/cRk2obijM5K9/?ref=app
+ 8
asking. do you know how to use cin?
+ 7
you can do that.. its just an example to show how to iterate a string
edit: lol yeah tiny tiny keyboard on my phone. the . is too close to space
+ 7
Ok. Change string myString = "A string";
to
string myString;
getline(cin, myString);
we use getline with cin to capture the whole input including spaces.
if we just used cin. it would cut off everything after a space.
If you have anymore questions please ask.
+ 7
https://code.sololearn.com/cRk2obijM5K9/?ref=app
updated., try various length strings each time
+ 6
no it won't. it changes based on the strings length.
see myString.length()
+ 6
i will update the code to accept user input using getline to demonstrate this for you
+ 2
that is pretty cool ...
but I want to show the result indexed ... wise..
like on 0th position there is "m"...
on 2th position there is "n"...
I hope you get my point .
+ 2
answer should be.. like ..that.. but.. there's... no..need..of . initializing.. because.. there's..need..of.. user .. input..
+ 2
are you asking or telling ??
+ 2
please don't get me wrong ...
I am learner ...
I don't know much about Programming...
that's why I asked...this.. question...
and I am thankful to.. you...that you responded.. to.. my.. question.
+ 2
I know how to use ... it .. but..there.. is.. question...about.. dynamic size.. if user will enter the string of 15 char then your array of size 10 .. will get out of .. bound..
+ 2
ok thank...u
+ 2
Thank...you.. 🙏
0
#include <string>
string arr[10]={};
for(int i;i<10;i++){
cin>>arr[i];
}
0
if the length of the string is not fixed then??...
the array gonna be failed ...