Hello,
But when i try to compile my project g++ gave me this errors:
ubuntu@ubuntu-laptop:~/C++$ g++ ClientFile.cpp
ClientFile.cpp: In function ‘int main()’:
ClientFile.cpp:10: error: ‘ofstream’ was not declared in this scope
ClientFile.cpp:10: error: expected `;' before ‘outClientFile’
ClientFile.cpp:13: error: ‘outClientFile’ was not declared in this scope
ClientFile.cpp:15: error: ‘cerr’ was not declared in this scope
ClientFile.cpp:15: error: ‘endl’ was not declared in this scope
ClientFile.cpp:16: error: ‘exit’ was not declared in this scope
ClientFile.cpp:19: error: ‘cout’ was not declared in this scope
ClientFile.cpp:19: error: ‘endl’ was not declared in this scope
ClientFile.cpp:27: error: ‘cin’ was not declared in this scope
ClientFile.cpp:29: error: ‘outClientFile’ was not declared in this scope
And here is the code of the file:
#include <iostream>
#include <fstream> // Fluxo de arquivos
int main()
{
// Construtor ofstream abre arquivo
ofstream outClientFile( "Clients.dat", ios::out );
// Fecha o programa se não conseguir criar o arquivo
if ( !outClientFile ) // Operador ! sobrecarregado
{
cerr << "File could not be opened" << endl;
exit( 1 );
} // Fim do if
cout << "Enter the account, name, and balance." << endl
<< "Enter end-of-file to end the input.\n? ";
int account;
char name[ 30 ];
double balance;
// Lê conta, nome e saldo a partir de cin, então coloca no arquivo
while ( cin >> account >> name >> balance )
{
outClientFile << account << ' ' << name << ' ' << balance << endl;
cout << "?";
} // Fim do while
return 0; // Destruitor ofstream fecha o arquivo
} // Fim de main
What is wrong? Thanks!