Non va, mi da questi errori ofstream file;Originariamente inviato da Emulator ®
Potresti usare fstream.
Devi includere <fstream>, ecco un esempio:
Spero di esserti stato utile..Codice PHP:
ofstream file; //Dichiaro file
file.open("tuo_file.txt", ios::app); //Apro il file in modalità append
if (!file.is_open()) //Se il file non è stato aperto (il che potrebbe dire che è in uso o non esistente)
{
file.open("tuo_file.txt", ios::out); //Apro il file in modalità scrittura (riscrive il file da 0)
}
file << "questo andrà sul file..."; //Stampo su file
file.close(); //Chiudo il file
Compilatore: Default compiler
Esecuzione di g++.exe...
g++.exe "C:\Dev-Cpp\SenzaTitolo2.cpp" -o "C:\Dev-Cpp\SenzaTitolo2.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Dev-Cpp\SenzaTitolo2.cpp:3: error: `ofstream' does not name a type
C:\Dev-Cpp\SenzaTitolo2.cpp:5: error: expected constructor, destructor, or type conversion before '.' token
C:\Dev-Cpp\SenzaTitolo2.cpp:5: error: expected `,' or `;' before '.' token
C:\Dev-Cpp\SenzaTitolo2.cpp:7: error: expected unqualified-id before "if"
C:\Dev-Cpp\SenzaTitolo2.cpp:7: error: expected `,' or `;' before "if"
C:\Dev-Cpp\SenzaTitolo2.cpp:12: error: expected constructor, destructor, or type conversion before '<<' token
C:\Dev-Cpp\SenzaTitolo2.cpp:12: error: expected `,' or `;' before '<<' token
C:\Dev-Cpp\SenzaTitolo2.cpp:13: error: expected constructor, destructor, or type conversion before '.' token
C:\Dev-Cpp\SenzaTitolo2.cpp:13: error: expected `,' or `;' before '.' token
Esecuzione terminata