PDA

Показать полную графическую версию : iostream.h


Ambal
21-09-2005, 15:33
День добрый.

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


З.Ы. rpm -q gcc

gcc-3.3.2-6mdk

[mzd]
21-09-2005, 21:04
Попробуй поискать :) Введи в консоли
locate iostream.h
Если не найдешь, то попробуй переставить gcc и иже с ним.

Ambal
21-09-2005, 21:43
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
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
Единственное, что пока пришло в голову - неправильные пути gcc к заголовочным файлам. Попробуй их подкорректировать или воспользуйся советом mar

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

Zippy
23-09-2005, 10:39
Хм, всегда писал <iostream.h> и никогда таких проблем не было...

hasherfrog
23-09-2005, 12:46
Дабы не осталось непоняток:
[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
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
>> Не понимаю в чем вообще тут проблема
Вы когда столкнётесь с ней, поймёте.

Ambal
23-09-2005, 14:54
Спасибо.

Разобрался.

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

mar
23-09-2005, 16:32
а еще бывает полезно в явном виде указать: g++ -o имя_выходного_файла фалй.cpp

Zippy
23-09-2005, 17:38
а еще бывает полезней makefile делать :)

mar
23-09-2005, 19:21
Zippy
ну не на hello, world же :)

aESThete
24-09-2005, 10:22
to mar: А на чем тогда учиться makefile делать? ;)

Envel
24-09-2005, 23:13
#include <iostream>
main() {
std::cout<<"Hello!\n";
}

или

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




© OSzone.net 2001-2012