+ 3

Can anybody tell how to get input from user in vector of string in c++?

question about vector .

2nd Sep 2017, 1:30 AM
Abhishek Tripathi
Abhishek Tripathi - avatar
17 Respuestas
+ 11
is this what you are looking for? https://code.sololearn.com/cANf9UlPmEGM/?ref=app
2nd Sep 2017, 1:59 AM
jay
jay - avatar
+ 9
https://code.sololearn.com/cRk2obijM5K9/?ref=app
2nd Sep 2017, 2:58 AM
jay
jay - avatar
+ 8
asking. do you know how to use cin?
2nd Sep 2017, 3:18 AM
jay
jay - avatar
+ 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
2nd Sep 2017, 3:15 AM
jay
jay - avatar
+ 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.
2nd Sep 2017, 3:21 AM
jay
jay - avatar
+ 7
https://code.sololearn.com/cRk2obijM5K9/?ref=app updated., try various length strings each time
2nd Sep 2017, 3:26 AM
jay
jay - avatar
+ 6
no it won't. it changes based on the strings length. see myString.length()
2nd Sep 2017, 3:22 AM
jay
jay - avatar
+ 6
i will update the code to accept user input using getline to demonstrate this for you
2nd Sep 2017, 3:24 AM
jay
jay - avatar
+ 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 .
2nd Sep 2017, 2:27 AM
Abhishek Tripathi
Abhishek Tripathi - avatar
+ 2
answer should be.. like ..that.. but.. there's... no..need..of . initializing.. because.. there's..need..of.. user .. input..
2nd Sep 2017, 3:11 AM
Abhishek Tripathi
Abhishek Tripathi - avatar
+ 2
are you asking or telling ??
2nd Sep 2017, 3:16 AM
Abhishek Tripathi
Abhishek Tripathi - avatar
+ 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.
2nd Sep 2017, 3:18 AM
Abhishek Tripathi
Abhishek Tripathi - avatar
+ 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..
2nd Sep 2017, 3:21 AM
Abhishek Tripathi
Abhishek Tripathi - avatar
+ 2
ok thank...u
2nd Sep 2017, 3:24 AM
Abhishek Tripathi
Abhishek Tripathi - avatar
+ 2
Thank...you.. 🙏
2nd Sep 2017, 3:28 AM
Abhishek Tripathi
Abhishek Tripathi - avatar
0
#include <string> string arr[10]={}; for(int i;i<10;i++){ cin>>arr[i]; }
2nd Sep 2017, 1:47 AM
Fillipe Meireles
Fillipe Meireles - avatar
0
if the length of the string is not fixed then??... the array gonna be failed ...
2nd Sep 2017, 1:50 AM
Abhishek Tripathi
Abhishek Tripathi - avatar