Results 1 to 6 of 6
this is a dumb question that i've figured out before, and prompty forgotten. I learned to program C++ in windows. im used to using cout<< and cin>>, however, when i ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 05-29-2003 #1Just Joined!
- Join Date
- May 2003
- Location
- Baltimore, MD
- Posts
- 26
newbie question
this is a dumb question that i've figured out before, and prompty forgotten. I learned to program C++ in windows. im used to using cout<< and cin>>, however, when i try to include<iostream.h> i get a billion errors, and when i include<iostream> im told that cout, endl, and cin (etc, etc) are "undeclared, first use this function"
so, my options are to use c-style printf and such, which i havent used in years, or i can try and figure out what im doing wrong with iostream.
thanks!
-Jordan
- 05-29-2003 #2Linux Engineer
- Join Date
- Nov 2002
- Location
- Queens, NY
- Posts
- 1,319
gcc/g++ version
Haz,
What version of gcc/g++ are you running? I'm betting that you are using something above 2.95. What bothers me here is that you should be able to use iostream.h (with dot h) without any problems. However, if you use iostream (without dot h), you'll need to declare the std namespace.The reason for this is because the new header files (without dot h) such as iostream, stdlib, and the rest of the new headers use a feature in C++ called namespaces. They are all scoped to 'std.' This is why in line 2, I have that statement. This tells the compiler everytime you see cout or cin, it's a part of the 'std' namespace. You can also do this another way.Code:#include <iostream> using namespace std; int main() { cout << "Damn these new header files!"; return 0; }
Here, I'm adding the actual namespace. Some programmers feel this way is a better method.Code:#include <iostream> // NOTE: no namepspace statement int main() { std::cout << "Another method"; return 0; }
Going back to iostream.h, I don't have an upgraded version of gcc so I can't see how the files are structured but iostream.h should work. Can you post a sample code using iostream.h that gives you can error?The best things in life are free.
- 05-30-2003 #3Just Joined!
- Join Date
- May 2003
- Location
- Baltimore, MD
- Posts
- 26
ok
i have gcc version 3.2
heres my test "helloworld.cpp":
<code>
//helloworld.cpp
#include<iostream.h>
int main() {
cout<<"Hello world!"<<endl;
return 0;
}
</code>
and i get quite a lot of errors like
"/tmp/cc0zGxdm.o: in fuction 'main':
/tmp/cc0xGxDm.o(.text+0x14): undefined reference to 'std::basic_ostream<char, std::char_traits<char> >&)' "
i get about a page of errors like that one.
-jordan
- 05-30-2003 #4Just Joined!
- Join Date
- May 2003
- Location
- Baltimore, MD
- Posts
- 26
also
also, i tried
include<iostream>
using namespace std;
and i get the same errors i do when i just include<iostream.h>
-jordan
- 05-30-2003 #5Just Joined!
- Join Date
- May 2003
- Location
- Baltimore, MD
- Posts
- 26
...
. . . and it all works just fine when i use g++ instead of gcc. any particular reason why?
whatever works, i guess....
-jordan
- 05-30-2003 #6Linux Engineer
- Join Date
- Nov 2002
- Location
- Queens, NY
- Posts
- 1,319
Which compiler are you using? If you are compiling for C++, you should stick to g++ since g++ is gcc with options for the C++ language. Now, does iostream.h work with g++? How about iostream with using namespaces?
The best things in life are free.


Reply With Quote
