0

ok, so i want a program that just says back to the user their input. the users input will be more then one word, so there will be whitespace. when i use string as a class for the input, then it only gives back the FIRST word of the input....
so i decided to use a vector, but i suck at them...
this is what i tried.. but on line 10, idk what to do :/ thnx!

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
        vector<string> s;
        string v;
        cin >> v;
        s.push_back(v);
        cout << endl << ????????; //all i want is to read all of the elements inside the vector, idk how....
}
4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by frogboy77
0

As suggested, a simple getline would get a line. Here is an example :

std::string input;
getline(cin,input);
//now input contains everything the user entered
0

ok. wud i do "getline(v, s)" ???
thnx. i thought getline was only for ifstream/ofstream stuff :P

0

I think he should have been able to figure that out from the hints provided. If not then there is no point in telling him.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.