The Str method for Stringstream will not work. (concatenation of different types) (C ++)

I am new to C ++ and I am trying to run a simple program.

I am 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 done automatically using the System.out.println () method.

What I was able to research was a good way to implement this in C ++ - 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 to compile this code, we get the following: The str method cannot be resolved.

I still need to find a solution on any web page. T Thank you!

+3
source share
3 answers

, include:

#include <sstream>

, , . :

#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();
}

+1

stringstream, #include <sstream>. stringstream std, , . .

+1

stringstream - just #include <sstream>

std::stringstream, std::string return ss.str() (, string output)

: using:: std ( ) . .: std

+1

All Articles