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??

Recommended Answers

All 2 Replies

You'll need to inisialise it with another method if you don't like getInput.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.