-6

I am trying to use << as a means of moving integers into a stringstream. There must be something fundamental and basic I am overlooking. The simplest of code does not even compile:

    std::stringstream ss;

    ss << "simple test ";

produces this error:

error C2297: '<<' : illegal, right operand has type 'const char [13]'

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
xarzu
  • 8,657
  • 40
  • 108
  • 160

2 Answers2

3

That is not a valid C++ program.

First, you need to include sstream. Then, you need to put that expression with << into a function.

Like this:

#include <sstream>

int main()
{
   std::stringstream ss;
   ss << "simple test ";
}
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

This worked:

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
    stringstream ss;
    string s;

    ss << "simple test ";

    s = ss.str();

    cout << s;

    return 0;
}