130

I am coding in Eclipse and have something like the following:

#include <ftream>
#include <iostream>

void read_file(){
    char buffer[1025];
    std::istringstream iss(buffer);
}

However, when I try to build, I get the following error: variable 'std::istringstream iss' has initializer but incomplete type

Any quick thoughts? I have googled around and it seems like most people with this problem simply did not include the right header files which I believe I am doing correctly.

Paolo
  • 20,112
  • 21
  • 72
  • 113
ElectronAnt
  • 2,115
  • 7
  • 22
  • 39

2 Answers2

297

You need this include:

#include <sstream>
sth
  • 222,467
  • 53
  • 283
  • 367
Jive Dadson
  • 16,680
  • 9
  • 52
  • 65
  • 30
    This is practically a bug on the standard library; the class was found but not the method leaving the programmer in the dark about what file to include unless he knows the standard library file names by heart, which is a ridiculous expectation. I hope someone reports it as a bug. – j riv Jul 09 '18 at 11:07
  • 1
    @jriv I am not sure what are you talking about. cppreference clearly states that the `sstream` header must be included to use `std::istringstream`. https://en.cppreference.com/w/cpp/io/basic_istringstream – Anis Ladram Oct 10 '20 at 22:11
  • 2
    @AnisLadramhe: he is talking about being mislead by `gcc` *error message*, which is not helping the programmer to abide by the standard. – ankostis May 07 '22 at 17:16
1

` Please include either of these:

`#include<sstream>`

using std::istringstream; 
devELIOper
  • 625
  • 5
  • 7