1

Re-post as I didn't include enough info in the last one.

I tried my best google fu and can't seem to find the right answer (doesn't mean it's not a stupid mistake, as I'm still new)

int main()
{
    vector<string> clauses;
    string test;

    cout << "Please enter your choice or choices\n\ ";

    while (cin >> test) {
        clauses.push_back(test);
    }

    return 0;
}

I don't know how many options they will enter so I'm throwing them in a vector.

Currently when it runs it won't take any user input and just let the person keep typing even when hitting enter. c

Thanks in advance. Paul

Danny_ds
  • 11,201
  • 1
  • 24
  • 46
pdsnowden
  • 37
  • 5

1 Answers1

1

The following code should work for what you want to do :

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

int main()
{
    std::vector<std::string> clauses;
    std::string test;

    std::cout << "Please enter your choice or choices\n";

    do
    {
        getline(std::cin, test);
        if(!test.empty())
            clauses.push_back(test);

    }while (!test.empty());

    return 0;
}

The getline function will read any text on the keyboard and push it in your vector until the user only use the Enter key, which will end the loop.

Izuka
  • 2,572
  • 5
  • 29
  • 34
  • 1
    Thanks so much Isuka. For anybody who finds this later through Google the code Isuka published works perfectly. – pdsnowden Jan 18 '16 at 23:10