Hey guys,
I am writing a C++ console app that carries on a conversation with the user. I need to be able to easily write functions that might take the user's input (type char), then make some decision about what to say, then finally return a value of type char. I would like to do it something like this... (leaving out irrelevant code)
I can get it to compile without any errors, but I don't get the right output, I get goofy control characters. You can put a function inside a cout statement as long as the function return a char, right?Code:char someFunction() { char output; ... ... // Decide what to say ... return output; } int main() { cout << someFunction() << endl; return 0; }
Just in case that's wrong, I also tried to get around that by doing this...
Didn't work either. I could just put the cout statement inside the function, but that defeats the whole purpose of using encapsulation. I need to be able to write many small functions that return char because I will probably change this to a GUI later and the cout statements become useless.Code:int main() { char word; strcpy(word, someFunction()); cout << word << endl; return 0; }
Why is it showing control characters? What am I doing wrong?



LinkBack URL
About LinkBacks


