0

Hi,

I have a string *input; and that variable is initalized with getInput();. I initialize input in setup(). setup() is run once. this is where my problem is: I'm looking for a better logic that let me initialize input without getting a prompt which came from getline(cin, line) that is inside getInput();

string* Controls::getInput(){
    static string sentence[4];
    string line;
    int i = 0;

    cout << ":>_";
    getline(cin, line);
    transform(line.begin(), line.end(), line.begin(), ::tolower);
    stringstream ss(line);

    for (int x = 0; x < 4; x++){
        sentence[x] = "null";
    }
    while (ss.good()) {
        ss >> sentence[i++];
    }
    while (i < 4){
        sentence[i++] = "null";
    }

    return sentence;
}

How should I proceed??

2
Contributors
2
Replies
10
Views
2 Years
Discussion Span
Last Post by HuePig
0

Hi, Ive decided to go with a new solution..

void Controls::getInput(){
    static string sentence[4];
    string line;
    int i = 0;
    cout << ":>_";
    getline(cin, line);
    transform(line.begin(), line.end(), line.begin(), ::tolower);
    stringstream ss(line);
    for (int x = 0; x < 4; x++){
        sentence[x] = "null";
    }
    while (ss.good()) {
        ss >> sentence[i++];
    }
    while (i < 4){
        sentence[i++] = "null";
    }
    input = sentence;
}

what do you think?

This question has already been answered. 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.