La funzione open
ha qualche tipo di restrizione su quale tipo di valore stringa viene passato?errore di compilazione: ifstream :: open accetta solo valori stringa tra virgolette "" e non variabili stringa
ifstream file;
string filename = "output.txt";
file.open(filename);
ho cercato di superare un valore di stringa con una variabile stringa, ma quando si tenta di compilare, il risultato è ...
agent.cpp:2:20: error: ofstream: No such file or directory
agent.cpp: In function ‘std::string readingline(std::string)’:
agent.cpp:11: error: aggregate ‘std::ifstream file’ has incomplete type and cannot be defined
agent.cpp: In function ‘int main()’:
agent.cpp:44: error: aggregate ‘std::ofstream writefile’ has incomplete type and cannot be defined
D'altra parte, quando appena passa una stringa valore tra virgolette come "nomefile.txt", compila bene e gira bene.
ifstream file;
file.open("output.txt");
Perché è questo il caso?
C'è un modo per risolvere questo problema?
hai provato a passare un puntatore a un array di caratteri? – neeKo
Vedere [Perché (i | o) fstream utilizza un parametro const char * per un nome file?] (Http://stackoverflow.com/questions/5972151/why-does-iofstream-take-a-const-char- parametro-per-un-nome-file) –