Discussion:
[GlugCEN] Ayuda en C++ con fstream
unknown
2007-05-05 20:16:21 UTC
Permalink
Hola gente, a ver quien me puede dar una mano con este código de ejemplo:

Tengo el siguiente código:
(sacado de acá http://www.cppreference.com/cppio/constructors.html)

#include <fstream
// #include <iostream>

int main(){
ifstream fin( "/tmp/data.txt" );
ofstream fout( "/tmp/results.txt", ios::app );
while( fin >> temp )
fout << temp + 2 << endl;
fin.close();
fout.close();
return 0;
}

Probe de compilarlo con estos g++ en estas distros:
g++ (GCC) 4.1.1 (Gentoo 4.1.1-r3)
g++-3.4 (GCC) 3.4.6 (Debian 3.4.6-5)
g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)

Los errores son más o menos estos, en las 3 distros con 3 versiones
distintas del g++:

$ g++ -o prueba prueba.cpp
prueba.cpp: In function 'int main()':
prueba.cpp:6: error: 'ifstream' was not declared in this scope
prueba.cpp:6: error: expected `;' before 'fin'
prueba.cpp:7: error: 'ofstream' was not declared in this scope
prueba.cpp:7: error: expected `;' before 'fout'
prueba.cpp:8: error: 'fin' was not declared in this scope
prueba.cpp:8: error: 'temp' was not declared in this scope
prueba.cpp:9: error: 'fout' was not declared in this scope
prueba.cpp:9: error: 'endl' was not declared in this scope
prueba.cpp:10: error: 'fin' was not declared in this scope
prueba.cpp:11: error: 'fout' was not declared in this scope

Alguna sugerencia???
Porque es que no encuentra la lib del fstream???
Me fijé varias veces y no falta ninguna otra...estoy medio desorientado...

Gracias gente,
Dami y Cele (haciendo tp).
unknown
2007-05-05 20:21:23 UTC
Permalink
Post by unknown
(sacado de acá http://www.cppreference.com/cppio/constructors.html)
#include <fstream
// #include <iostream>
int main(){
ifstream fin( "/tmp/data.txt" );
ofstream fout( "/tmp/results.txt", ios::app );
while( fin >> temp )
fout << temp + 2 << endl;
fin.close();
fout.close();
return 0;
}
g++ (GCC) 4.1.1 (Gentoo 4.1.1-r3)
g++-3.4 (GCC) 3.4.6 (Debian 3.4.6-5)
g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
Los errores son más o menos estos, en las 3 distros con 3 versiones
$ g++ -o prueba prueba.cpp
prueba.cpp:6: error: 'ifstream' was not declared in this scope
prueba.cpp:6: error: expected `;' before 'fin'
prueba.cpp:7: error: 'ofstream' was not declared in this scope
prueba.cpp:7: error: expected `;' before 'fout'
prueba.cpp:8: error: 'fin' was not declared in this scope
prueba.cpp:8: error: 'temp' was not declared in this scope
prueba.cpp:9: error: 'fout' was not declared in this scope
prueba.cpp:9: error: 'endl' was not declared in this scope
prueba.cpp:10: error: 'fin' was not declared in this scope
prueba.cpp:11: error: 'fout' was not declared in this scope
Alguna sugerencia???
Porque es que no encuentra la lib del fstream???
Me fijé varias veces y no falta ninguna otra...estoy medio desorientado...
Te falta el using namespace (*stream estan en std)
unknown
2007-05-05 20:43:41 UTC
Permalink
A noooooooooooooooooooooooooooooooo!!!
JODEME!
Eso me pasa por portear un código de C a C++ a los ponchasos.
Definitivamente no me gusta C++ pero los << y >> son más cómodos...

Gracias Max!
Dami y cele.
Post by unknown
Post by unknown
(sacado de acá http://www.cppreference.com/cppio/constructors.html)
#include <fstream
// #include <iostream>
int main(){
ifstream fin( "/tmp/data.txt" );
ofstream fout( "/tmp/results.txt", ios::app );
while( fin >> temp )
fout << temp + 2 << endl;
fin.close();
fout.close();
return 0;
}
g++ (GCC) 4.1.1 (Gentoo 4.1.1-r3)
g++-3.4 (GCC) 3.4.6 (Debian 3.4.6-5)
g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
Los errores son más o menos estos, en las 3 distros con 3 versiones
$ g++ -o prueba prueba.cpp
prueba.cpp:6: error: 'ifstream' was not declared in this scope
prueba.cpp:6: error: expected `;' before 'fin'
prueba.cpp:7: error: 'ofstream' was not declared in this scope
prueba.cpp:7: error: expected `;' before 'fout'
prueba.cpp:8: error: 'fin' was not declared in this scope
prueba.cpp:8: error: 'temp' was not declared in this scope
prueba.cpp:9: error: 'fout' was not declared in this scope
prueba.cpp:9: error: 'endl' was not declared in this scope
prueba.cpp:10: error: 'fin' was not declared in this scope
prueba.cpp:11: error: 'fout' was not declared in this scope
Alguna sugerencia???
Porque es que no encuentra la lib del fstream???
Me fijé varias veces y no falta ninguna otra...estoy medio desorientado...
Te falta el using namespace (*stream estan en std)
_______________________________________________
Glug mailing list
http://glugcen.dc.uba.ar/cgi-bin/mailman/listinfo/glug
Loading...