Problem with returning strings
Feb 13, 2014 at 5:35am UTC
Hey guys, what exactly have I done wrong here? I'm trying to return a string from a function to concatenate onto my question but it fails to display the question first.
Much appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <string>
#include <iostream>
using namespace std;
string askName(string question);
int main() {
string name = askName("What is your name?" );
cout << "Your name is: " << name << "\n\n" ;
return 0;
}
string askName(string question) {
string message;
cin >> message;
return message;
}
Feb 13, 2014 at 5:51am UTC
I'm trying to return a string from a function to concatenate onto my question but it fails to display the question first.
That might be because you never display the question. For instance, where in
askName do you do anything with the parameter
question ?
Feb 13, 2014 at 6:02am UTC
Holy S**t I'm blind.
cout << question;
Thanks man. Haha.
Topic archived. No new replies allowed.