Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Программирование в *nix (http://forum.oszone.net/forumdisplay.php?f=35)
-   -   iostream.h (http://forum.oszone.net/showthread.php?t=54111)

Ambal 21-09-2005 15:33 357191

iostream.h
 
День добрый.

Решил я научиться программировать на С. Скачал книжку "Осовй С++ за 21 день". Замечательная книжка, все понятно, вот только С++-совскую библиотеку мой gcc не знает, в usr/gcclib я ее не нашел. Вопрос: эта библиотека исключительно для вин, я чего-то не доставил или у меня старая версия компилятора?


З.Ы. rpm -q gcc

gcc-3.3.2-6mdk

[mzd] 21-09-2005 21:04 357317

Попробуй поискать :) Введи в консоли
Код:

locate iostream.h
Если не найдешь, то попробуй переставить gcc и иже с ним.

Ambal 21-09-2005 21:43 357324

ocate iostream.h
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/2.96/include/iostream.h
/usr/include/c++/3.3.2/backward/iostream.h
/usr/include/c++/3.4.0/backward/iostream.h


gcc tt.c
tt.c:1:21: iostream.h: No such file or directory
tt.c: In function `main':
tt.c:7: error: `cout' undeclared (first use in this function)


Доставил все касаемо gcc, но результат такой же. Что делать?




mar 21-09-2005 22:33 357328

Ambal
попробуйте компилировать, используя g++
Пример:
Код:

$cat hello.cpp
#include <iostream.h>
main() {
    cout << "Hello, world\n";
}
g++ hello hello.cpp
$ls -l
-rwxr-xr-x  1 mar  wheel  6387 21 сен 22:26 hello
-rw-r--r--  1 mar  wheel    69 21 сен 22:25 hello.cpp
$./hello
Hello, world
$

и еще, давайте все-таки будем различать C и C++ ;)

[mzd] 22-09-2005 09:29 357431

Единственное, что пока пришло в голову - неправильные пути gcc к заголовочным файлам. Попробуй их подкорректировать или воспользуйся советом mar

Ambal 22-09-2005 17:39 357640

g++ hello.cpp
In file included from /usr/include/c++/3.3.2/backward/iostream.h:31,
from hello.cpp:1:
/usr/include/c++/3.3.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 <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
hello.cpp:12:2: warning: no newline at end of file

Не то чтобы я не понимаю английский, но что это значит?
Программа не компилируется.

hasherfrog 23-09-2005 02:07 357776

Старая фишка. Не забывайте использовать using namespace std; после #include и помните, что компилятор использует синтаксис с или с++ исходя из расширения файлов с или cpp. ЕМНИП: <iostream.h> используется для С, <iostream> для С++. Эта фишка выплывает раз в месяц у кого-нибудь из наших программеров раз в два месяца точно :]

Zippy 23-09-2005 10:39 357876

Хм, всегда писал <iostream.h> и никогда таких проблем не было...

hasherfrog 23-09-2005 12:46 357930

Дабы не осталось непоняток:
Код:

[hasherfrog@********* hasherfrog]$ more 1.cpp
#include <iostream>

main() {
    cout << "Hello, world\n";
}

[hasherfrog@********* hasherfrog]$ more 1.c
#include <iostream.h>
main() {
    cout << "Hello, world\n";
}

[hasherfrog@********* hasherfrog]$ more correct.cpp
#include <iostream>
using namespace std;

main() {
    cout << "Hello, world\n";
}

[hasherfrog@********* hasherfrog]$ more with_keys.cpp
#include <iostream.h>

main() {
    cout << "Hello, world\n";
}

Компилим
Код:

[hasherfrog@********* hasherfrog]$ g++ 1.c
In file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
                from 1.c:1:
/usr/include/c++/3.2.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 <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.

[hasherfrog@********* hasherfrog]$ g++ 1.cpp
1.cpp: In function `int main()':
1.cpp:4: `cout' undeclared (first use this function)
1.cpp:4: (Each undeclared identifier is reported only once for each function it
  appears in.)

[hasherfrog@********* hasherfrog]$ gcc 1.cpp
1.cpp: In function `int main()':
1.cpp:4: `cout' undeclared (first use this function)
1.cpp:4: (Each undeclared identifier is reported only once for each function it
  appears in.)

[hasherfrog@********* hasherfrog]$ gcc 1.c
1.c:1:22: iostream.h: No such file or directory
1.c: In function `main':
1.c:3: `cout' undeclared (first use in this function)
1.c:3: (Each undeclared identifier is reported only once
1.c:3: for each function it appears in.)

[hasherfrog@********* hasherfrog]$ gcc correct.cpp
/tmp/ccrilZvg.o(.text+0x19): In function `main':
: undefined reference to `std::cout'
/tmp/ccrilZvg.o(.text+0x1e): 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*)'
/tmp/ccrilZvg.o(.text+0x4a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccrilZvg.o(.text+0x79): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccrilZvg.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

[hasherfrog@********* hasherfrog]$ g++ correct.cpp
[hasherfrog@********* hasherfrog]$

[hasherfrog@********* hasherfrog]$ g++ 1.c  -Wno-deprecated
[hasherfrog@********* hasherfrog]$

[hasherfrog@********* hasherfrog]$ g++ with_keys.cpp  -Wno-deprecated
[hasherfrog@********* hasherfrog]$


Zippy 23-09-2005 13:05 357939

Код:

bash-2.05b$ more 1.cpp
 #include <iostream.h>
 int main()
 {
  cout << "Hello, World!" << endl;
 }

Код:

bash-2.05b$ g++ 1.cpp
 bash-2.05b$

Не понимаю в чем вообще тут проблема, зачем выдумывать велосипед?
Понятно, что при компиляции файлов "с" g++ и файлов "cpp" gcc будет ошибка!

hasherfrog 23-09-2005 13:25 357956

>> Не понимаю в чем вообще тут проблема
Вы когда столкнётесь с ней, поймёте.

Ambal 23-09-2005 14:54 357986

Спасибо.

Разобрался.

using namespace std; - то, что мне было нужно



mar 23-09-2005 16:32 358024

а еще бывает полезно в явном виде указать:
Код:

g++ -o имя_выходного_файла фалй.cpp

Zippy 23-09-2005 17:38 358069

а еще бывает полезней makefile делать :)

mar 23-09-2005 19:21 358109

Zippy
ну не на hello, world же :)

aESThete 24-09-2005 10:22 358244

to mar: А на чем тогда учиться makefile делать? ;)

Envel 24-09-2005 23:13 358382

#include <iostream>
main() {
std::cout<<"Hello!\n";
}

или

#include <iostream>
using namespace stdl
main() {
cout<<"Hello!\n";
}


Время: 16:06.

Время: 16:06.
© OSzone.net 2001-