3

I have a previously declared char c[64]; and I'm trying to look at the first word of the output of a pipe:

read(pipe_replacement_to_main[READ_END], c, BUF_SIZE);
istringstream response_stream(string(c));
string response_string;
getline(response_stream, response_string, ' ');

And gcc gives me the following at that fourth line:

error: no matching function for call to ‘getline(std::istringstream (&)(std::string), std::string&, char)’

I can't even figure out how it's trying to call the function. Did I declare the istringstream wrong?

Shay Guy
  • 980
  • 1
  • 7
  • 18

2 Answers2

5

Most vexing parse, add a pair of parenthesis inside the constructor of response_stream.

istringstream response_stream((string(c)));
Community
  • 1
  • 1
Xeo
  • 126,658
  • 49
  • 285
  • 389
2

A nice demonstration of the true "power" of C++.

The way you declared the response_stream variable, it is actually a function rather than type istringstream.

Fyodor Soikin
  • 74,930
  • 8
  • 118
  • 160