C++ compile error: has initializer but incomplete type
Asked Answered
B

2

132

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.

Broca answered 17/11, 2012 at 6:3 Comment(5)
std::istringstring? It's in the <sstream> header anyway, though.Dubbin
whoops, i typed the question wrong, i have it coded the way you wrote so the problem is still the sameBroca
yep, adding <sstream> made it build correctly, thanks!Broca
Hard to see what the justification is for reopening. I'll skip and let others make the decision, but it appears to be a simple error.Molest
Also, I believe the first line should be #include<fstream> instead of #include <ftream> @AneemLemley
P
303

You need this include:

#include <sstream>
Percent answered 17/11, 2012 at 7:13 Comment(3)
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.Yasmineyasu
@jriv I am not sure what are you talking about. cppreference clearly states that the sstream header must be included to use std::istringstream. en.cppreference.com/w/cpp/io/basic_istringstreamTilbury
@AnisLadramhe: he is talking about being mislead by gcc error message, which is not helping the programmer to abide by the standard.Ceil
B
1

Please include either of these:

#include<sstream>

using std::istringstream;
Blubbery answered 2/12, 2020 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.