Scusate se questo è abbastanza noobish, ma sono piuttosto nuovo di C++. Sto cercando di aprire un file e leggerlo con ifstream
:C++: la variabile 'std :: ifstream ifs' ha l'inizializzatore ma il tipo è incompleto
vector<string> load_f(string file) {
vector<string> text;
ifstream ifs(file);
string buffer, str_line;
int brackets = 0;
str_line = "";
while (getline(ifs, buffer)) {
buffer = Trim(buffer);
size_t s = buffer.find_first_of("()");
if (s == string::npos) str_line += "" + buffer;
else {
while (s != string::npos) {
str_line += "" + buffer.substr(0, s + 1);
brackets += (buffer[s] == '(' ? 1 : -1);
if (brackets == 0) {
text.push_back(str_line);
str_line = "";
}
buffer = buffer.substr(s + 1);
s = buffer.find_first_of("()");
}
}
}
return text;
}
Tuttavia, sto ottenendo il seguente errore io non sono molto sicuro come risolvere il problema:
variable 'std::ifstream ifs' has initializer but incomplete type
risposte molto apprezzati . Si noti che non ho mai dimenticato di #include <fstream>
, dal momento che molti hanno ricevuto l'errore a causa semplicemente dimenticando di includere l'intestazione.
EDIT:
scopre che in realtà ho fatto dimenticare di includere fstream
, ma avevo dimenticato a causa di spostare la funzione di un altro file.
Leggere la fine della domanda. ;) – beakr
si dovrebbe 1) ans – Pubby
Questa risposta mi ha aiutato. Nel mio caso, è stato perché ho rimosso un altro file di intestazione che includeva fstream. La soluzione doveva includere fstream. –