Emanuel Steen
kozz at pegasos.org
Sön Feb 11 09:40:08 GMT 2007
Hej Peter,
Det är iostream som skall inkluderas i C++ och inte iostream.h.
Nästa grej är att cout out endl ligger i ett namespace, i detta fallet
namespace std. Antingen får man använda "std::cout" respektive
"std::endl" eller använda sig av "using namespace std;" innan man
använder cout och endl.
#include <iostream>
int main()
{
std::cout << "Test" << std::endl;
return 0;
}
Det programmet fungerar.
Alternativt.
#include <iostream>
using namespace std;
int main()
{
cout << "Test" << endl;
return 0;
}
// Emanuel
Peter wrote:
> Hej.
> Sitter och försöker lära mig lite C++ programmering och får lite
> konstigt resultat. Koden jag kompilerar är följande med namnet
> test.cpp (raderna med START och SLUT är inte med)
>
> --- START---
> #include <iostream.h>
>
> int main()
> {
> cout << "Test" << endl;
> return 0;
> }
>
> ---SLUT---
>
>
> När jag kompilerar test.cpp med "g++ test.cpp -o test" från
> kommandoraden får jag följande meddelande
>
> --- KLIPP ---
> g++ test.cpp -o test
> In file included from
> /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/iostream.h:31,
> from test.cpp:1:
> /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2:
> warning: #warning This file includes at least one deprecated or
> antiquated header. Please consider using one of the 32 headers found
> in section 17.4.1.2 of the C++ standard. Examples include substituting
> the <X> header for the <X.h> header for C++ includes, or <iostream>
> instead of the deprecated header <iostream.h>. To disable this warning
> use -Wno-deprecated.
>
> --- KLIPP ---
>
> När jag sedan försöker använda enbart #include <iostream> får jag
> följande meddelande:
>
> --- KLIPP---
> test.cpp: In function ‘int main()’:
> test.cpp:5: error: ‘cout’ was not declared in this scope
> test.cpp:5: error: ‘endl’ was not declared in this scope
> --- KLIPP---
>
> Jag har kollat så filen iostream finns i /usr/include/c++/4.1.2 men
> något är fel???
>
> Är det någon som har tips om vad som kan vara fel?
>
>
> // Peter
>
-------------- next part --------------
En HTML-bilaga skiljdes ut...
URL: https://lists.ubuntu.com/archives/ubuntu-se/attachments/20070211/4aef9ead/attachment.htm
More information about the ubuntu-se
mailing list