-5

I have some strings and 3 integers and I want to put them all in a string and return them. That's the error I get with this code:

string Car::infoCar(){
       stringstream str;

       str<< manufacturer << " " << model << " " << AK << " " << cspeed << " " << maxspeed << " " << cgear; 
       return str.toString();
}

Also I use:

#include <sstream>
#include <string>

using namespace std;

The same error I do get when I run my other homework as well using the same way.

  • [Be wary of `using namespace std;`](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) TL;DR there are a lot of classes, structures, functions, and other useful things in the standard library. Some of them may have the same name as your stuff and, if the compiler doesn't choke over the re-used names, the compiler may choose to use the library version rather than yours. Comic hi-jinks ensue. – user4581301 Nov 20 '15 at 20:02
  • I'll give it a try and let you know, thanks for the help! –  Nov 20 '15 at 20:10

3 Answers3

2

The function you're looking for is called str:

return str.str();
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
  • it opens a makefile.win when i run this, take a look at the [image](http://prntscr.com/950erd) for the error –  Nov 20 '15 at 19:53
  • Seems like another, unrelated problem. Please post it as a new question. – Emil Laine Nov 20 '15 at 19:58
2

cppreference.com is your friend. C++ isn't java or C#.

http://en.cppreference.com/w/cpp/io/basic_stringstream/str

Edward Strange
  • 40,307
  • 7
  • 73
  • 125
2

Yep the method is called str()

http://www.cplusplus.com/reference/sstream/stringstream/str/

 // Replace
 return str.toString();

 // With
 return str.str();
Martin York
  • 257,169
  • 86
  • 333
  • 562
  • it opens a makefile.win when i run this, take a look at the [image](http://prntscr.com/950erd) for the error –  Nov 20 '15 at 19:54