I'm brand new to C++ and I am trying to get a simple program up and running.
I'm using the Eclipse IDE ( C++ Version ) on a Windows System.
I am trying to concatenate an output statement, it will combine numbers and strings.
I know in Java, this was automatically done with the System.out.println() method.
What I was able to research was a nice way of implementing this in C++ is to use the string stream method.
#include <iostream>
#include <string>
#include "Person.h"
...
string simpleOutput(){
stringstream ss;
int a = 50; // for testing purposes
int b = 60;
string temp = "Random";
ss << a << b << temp;
return string output = ss.str();
}
When I try compiling this code is get the following: "Method "str" could not be resolved.
I have yet to find a solution on any webpage. T Thank you!
Your primary problem is that you're missing an include:
#include <sstream>
Also, you have a typo in the function, and your return statement is downright crazy. With these fixes, it works:
#include <iostream>
#include <string>
#include <sstream>
string simpleOutput(){
stringstream ss;
int a = 50; // for testing purposes
int b = 60;
string temp = "Random";
ss << a << b << temp;
return ss.str();
}
See it live
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With