Помогите начинающему программисту

Все о программировании под *nix
Аватара пользователя
Lito
Интересующийся
Сообщения: 50
Зарегистрирован: 22 мар 2007, 22:09
Откуда: Лида
Контактная информация:

Помогите начинающему программисту

Сообщение Lito »

В школе изучаю Паскаль и всё вроде бы хорошо, но вот чего то на С++ потянуло. Беру простенькую программу из документации

Код: Выделить всё

#include <iostream>
 main()
 {
     cout << "Hello, world\n";
 }
[kirill@localhost C]$ gcc world.cpp
In file included from /usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../../include/c++/3.4.3/backward/iostream.h:31,
from world.cpp:1:
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../../include/c++/3.4.3/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> header for C++ includes, or <iostream> instead of the deprecated header <iostream>. To disable this warning use -Wno-deprecated.
world.cpp:6:4: warning: no newline at end of file
/home/kirill/tmp/ccFcAq8R.o(.text+0xd): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/home/kirill/tmp/ccFcAq8R.o(.text+0x60): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/home/kirill/tmp/ccFcAq8R.o(.text+0x9d): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/home/kirill/tmp/ccFcAq8R.o(.text+0xc8): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/home/kirill/tmp/ccFcAq8R.o(.text+0x129): In function `main':
: undefined reference to `std::cout'
/home/kirill/tmp/ccFcAq8R.o(.text+0x12e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/home/kirill/tmp/ccFcAq8R.o(.text+0x15a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init()'
/home/kirill/tmp/ccFcAq8R.o(.text+0x189): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init()'
/home/kirill/tmp/ccFcAq8R.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Меняю iostream.h на iostream и:
[kirill@localhost C]$ gcc world.cpp
world.cpp: In function `int main()':
world.cpp:4: error: `cout' undeclared (first use this function)
world.cpp:4: error: (Each undeclared identifier is reported only once for each function it appears in.)
world.cpp:6:4: warning: no newline at end of file
Что не так? :?
P.S. У меня Мандрива 2005
Don't shout at me... I'm only a learner...

michael
Неотъемлемая часть форума
Сообщения: 434
Зарегистрирован: 12 апр 2004, 11:00
Откуда: г. Владивосток
Контактная информация:

Сообщение michael »

1) Пиши std::cout вместо cout или помести строку using namespace std; перед main. Похоже, документация старая и вопрос о namespace'ах в ней не освещён.
2) warning: no newline at end of file - это понятно. Ентер нажми после последней закрывающей }
3) Используй g++ вместо gcc.
4) Компилятор лучше вызывать так: g++ -o <_> world.cpp

Аватара пользователя
Lito
Интересующийся
Сообщения: 50
Зарегистрирован: 22 мар 2007, 22:09
Откуда: Лида
Контактная информация:

Сообщение Lito »

michael, Ок. Спасибо большое!
Don't shout at me... I'm only a learner...

Ответить