I have been learning C++ for a little while now but have only used any of it on Windows. I wanted to try it out on Linux, so I made the simplest thing I possibly could:
#include <iostream.h>
int main()
{
cout << "Hello\n";
return(0);
}
And tried "gcc test2.cpp" to compile it, test2.cpp of course being the filename. Well, this is what it said:
In file included from /usr/include/c++/3.2/backward/iostream.h:31,
from test2.cpp:1:
/usr/include/c++/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.
test2.cpp:7:2: warning: no newline at end of file
/tmp/ccA1TBCY.o(.text+0x19): In function `main':
: undefined reference to `std::cout'
/tmp/ccA1TBCY.o(.text+0x1e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std: :o perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccA1TBCY.o(.text+0x4a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccA1TBCY.o(.text+0x79): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccA1TBCY.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
I then searched for iostream* and found that there is iostream and iostream.h. So I then tried
#include </usr/include/c++/3.2/iostream>
int main()
{
cout << "Hello\n";
return(0);
}
Then it said
test2.cpp: In function `int main()':
test2.cpp:5: `cout' undeclared (first use this function)
test2.cpp:5: (Each undeclared identifier is reported only once for each
function it appears in.)
And that just kinda stumped me, so I did some reading and changed it to:
#include <istream>
int main()
{
printf("Hello\n");
return(0);
}
Which worked. My question is, why isn't iostream working right for me? Is the code really that different between Windows and Linux, and what I'm trying to do just doesn't make any sense (I sure hope not)? I also remember reading that printf is outdated, what's up with that? Any ideas will be appreciated.
(Edit: 1) disabled smilies. 2) fixed a problem with the filenames to reduce confusion. 3) that wasn't the best choice for a thread title, was it?)
[ September 27, 2003: Message edited by: Dirk Gently ]