0

im trying to get the data from a string variable and put it into its own place in a string vector but it saves each word as its own point in the vector.

i.e. "buy milk" will result in 0 being buy then 1 being milk not 0 being buy milk.

sorry for not knowing the proper terminology im really new to C++

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string input;
    vector <string> Notes;
    int SaveNoteOnLine = 0;
    string output; //a var needed for specific situations, not used for all output

    cout << "welcome to cmdnotes alpha v1.0\n";
    while (true) {
        cin >> input;
        if (input == "-list") {
            for (int i = 0; i < SaveNoteOnLine; i++) {
                cout << Notes.at(i) << endl;
            }
        }
        else {
            Notes.push_back(input);
            cout << "saved on line " << SaveNoteOnLine << endl;
            SaveNoteOnLine++;
        }
    }
}

1 Answers1

1

Use getline(cin,input) inplace of cin>>input it will take whitespaces as input

Rahul Khanna
  • 127
  • 1
  • 11