OVH Cloud OVH Cloud

erreur avec dev c++

1 réponse
Avatar
giovanni
me dit erreur :
C:\Dev-Cpp\main.cpp In function `int main()':
45 C:\Dev-Cpp\main.cpp `TEXT' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it
appears in.)
45 C:\Dev-Cpp\main.cpp variable `std::ifstream input' has initializer but
incomplete type
C:\Dev-Cpp\Makefile.win [Build Error] [main.o] Error 1

#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>
#include <string>

void display( int line_num , int v1 , int v2 , int v3 , int v4 ) {
std::cout
<< "# " << line_num << ":\t"
<< "v1: " << v1
<< ", v2: " << v2
<< ", v3: " << v3
<< ", v4: " << v4
<< std::endl ;
}

void format_error( int line_num ) {
std::cerr << "Error at line " << line_num << "!\n" ;
}

bool is_space( std::string const & s ) {
for ( std::string::const_iterator it = s.begin() ,
end = s.end() ;
it != end ;
++ it ) {
char c = * it ;
if ( ! std::isspace( c ) ) {
return false ;
}
}
return true ;
}

bool is_space( std::istringstream & iss ) {
for ( char c = iss.get() ; iss ; c = iss.get() ) {
if ( ! std::isspace( c ) ) {
return false ;
}
}
return true ;
}

int main() {
const char* nome_del_file = "c:/";
std::ifstream input(TEXT.TXT);
for ( int line_num = 1 ; input ; ++ line_num ) {
std::string line ;
std::getline( input , line ) ;


if ( is_space( line ) ) {
std::cout << "# " << line_num << ":\tempty" << std::endl ;
continue ;
}

int v1 = 0 , v2 = 0 , v3 = 0 , v4 = 0 ;
std::istringstream iss( line ) ;
iss >> v1 >> v2 >> v3 >> v4 ;

if ( iss && is_space( iss ) ) {
display( line_num , v1 , v2 , v3 , v4 ) ;
}
else {
format_error( line_num ) ;
break ;
}
}
}

1 réponse

Avatar
Gabriel Dos Reis
"giovanni" writes:

| me dit erreur :
| C:Dev-Cppmain.cpp In function `int main()':
| 45 C:Dev-Cppmain.cpp `TEXT' undeclared (first use this function)
| (Each undeclared identifier is reported only once for each function it
| appears in.)
| 45 C:Dev-Cppmain.cpp variable `std::ifstream input' has initializer but
| incomplete type
| C:Dev-CppMakefile.win [Build Error] [main.o] Error 1

Le compilateur a tout dit.

| #include <iostream>
| #include <istream>
| #include <ostream>
| #include <sstream>
| #include <string>

[...]

| int main() {
| const char* nome_del_file = "c:/";
| std::ifstream input(TEXT.TXT);

Tu voulais dire

std::ifstream input("TEXT.TXT");

note les guillemets. De plus il te faut

#include <fstream>

en début de programme.


-- Gaby