Prev: reinterpret_cast
Next: Discards qualifiers
From: Cheerful Pickle on 15 Feb 2006 08:02 Hi, gang, About 24 years ago, I got into programming with my old Commodore 64. I got to be quite good with both BASIC and with 6502/6510 assembly language programming. When the IBM PC came out, not finding the resources at the time to program with it (except for its nearly worthless version of BASIC), I let my programming die. I went on from DOS to Windows. Then I decided to take Bill Gates' advise when he says, "Windows 98 or better," so I went way better, all the way to Linux. This is now giving me the impetus to get back into programming. I started out with my only knowledge of c++ as being it is a compiled language, and that it is a derivative of c. Not much to start with, but one has to start somewhere. I went out and bought a book on C++ programming, _C++ for Dummies_. That is where my problems started. I can't seem to do anything right with it. Not having the ability to run the GNU compiler that came on the disk with the book, I have to use the GNU compiler that came built into my Linux, gcc. I copied the first program out of the book as follows: // Program to convert temperature from Celsius degree // units into Fahrenheit degree units: // Fahrenheit = Celsius * (212-32)/100 + 32 // #include <stdio.h> #include <iostream.h> int main(int nNumberofArgs, char* pszArgs[]) { // enter the temperature in Celsius int celsius; cout << "Enter the temperature in Celsius:"; cin >> celsius; // calculate conversion factor for Celsius // to Fahrenheit int factor; factor = 212 - 32; // use conversion factor to convert Celsius // into Fahrenheit values int fahrenheit; fahrenheit = factor * celsius/100 + 32; // output the results cout << "Fahrenheit value is:"; cout << fahrenheit; return 0; } However, when I went to compile it, instead of getting a compiled program, I got the following mess of error messages: [andy(a)localhost C++Lessons]$ gcc conversion.cpp In file included from /usr/lib/gcc/i586-mandriva-linux-gnu/4.0.1/../../../../inc lude/c++/4.0.1/backward/iostream.h:31, from conversion.cpp:6: /usr/lib/gcc/i586-mandriva-linux-gnu/4.0.1/../../../../include/c++/4.0.1/backwar d/backward_warning.h:32:2: warning: #warning This file includes at least one dep recated 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> h eader for the <X.h> header for C++ includes, or <iostream> instead of the deprec ated header <iostream.h>. To disable this warning use -Wno-deprecated. /home/andy/tmp/ccN6G3ui.o: In function `main': conversion.cpp:(.text+0x25): undefined reference to `std::cout' conversion.cpp:(.text+0x2a): undefined reference to `std::basic_ostream<char, st d::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ost ream<char, std::char_traits<char> >&, char const*)' conversion.cpp:(.text+0x39): undefined reference to `std::cin' conversion.cpp:(.text+0x3e): undefined reference to `std::basic_istream<char, st d::char_traits<char> >::operator>>(int&)' conversion.cpp:(.text+0x7e): undefined reference to `std::cout' conversion.cpp:(.text+0x83): undefined reference to `std::basic_ostream<char, st d::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ost ream<char, std::char_traits<char> >&, char const*)' conversion.cpp:(.text+0x91): undefined reference to `std::cout' conversion.cpp:(.text+0x96): undefined reference to `std::basic_ostream<char, st d::char_traits<char> >::operator<<(int)' /home/andy/tmp/ccN6G3ui.o: In function `__tcf_0': conversion.cpp:(.text+0xb3): undefined reference to `std::ios_base::Init::~Init( )' /home/andy/tmp/ccN6G3ui.o: In function `__static_initialization_and_destruction_ 0(int, int)': conversion.cpp:(.text+0xe0): undefined reference to `std::ios_base::Init::Init() ' /home/andy/tmp/ccN6G3ui.o:(.eh_frame+0x11): undefined reference to `__gxx_person ality_v0' collect2: ld returned 1 exit status [andy(a)localhost C++Lessons]$ YUK!!!!!!!! In trying to make heads or tails out of that mess of error messages, I changed iostream.h to iostream and that reduced my error messages down to the following: [andy(a)localhost C++Lessons]$ gcc conversion.cpp conversion.cpp: In function 'int main(int, char**)': conversion.cpp:12: error: 'cout' was not declared in this scope conversion.cpp:13: error: 'cin' was not declared in this scope [andy(a)localhost C++Lessons]$ I see nothing in the %^*$*(&% book to give me a clue as to what all this means. I hope I don't have the same problem with the next zillion programs. Newbie needs help. What am I doing wrong? Is this any way to learn c++??????????? -- Andy Rugg The Cheerful Pickle
From: R. Scott Mellow on 15 Feb 2006 09:16 Cheerful Pickle wrote: > Hi, gang, Hi. > I went out and bought a book on C++ programming, _C++ for Dummies_. That > is where my problems started. I can't seem to do anything right with it. Burn that book. Search the archives of this group for book recommendations. > In trying to make heads or tails out of that mess of error messages, I > changed iostream.h to iostream and that reduced my error messages down to > the following: > > [andy(a)localhost C++Lessons]$ gcc conversion.cpp > conversion.cpp: In function 'int main(int, char**)': > conversion.cpp:12: error: 'cout' was not declared in this scope > conversion.cpp:13: error: 'cin' was not declared in this scope > [andy(a)localhost C++Lessons]$ > > I see nothing in the %^*$*(&% book to give me a clue as to what all this > means. I hope I don't have the same problem with the next zillion > programs. Newbie needs help. What am I doing wrong? <iostream> is correct. However, all standard identifiers, e.g. cin and cout, live in a namespace named std and you need to use their fully qualified names, e.g. std::cout and std::cin. There are a couple of ways to avoid typing the fully qualified names but I'm not going to mention them. Here is an example program for you to try: #include <iostream> int main() { std::cout << "Hello World!\n"; return 0; } > > Is this any way to learn c++??????????? No, get a better book. -- Randy
From: Jim Langston on 15 Feb 2006 09:28 "Cheerful Pickle" <cp(a)no.junk> wrote in message news:pan.2006.02.15.13.02.16.400122(a)no.junk... > Hi, gang, > > About 24 years ago, I got into programming with my old Commodore 64. I > got to be quite good with both BASIC and with 6502/6510 assembly language > programming. When the IBM PC came out, not finding the resources at the > time to program with it (except for its nearly worthless version of > BASIC), I let my programming die. I went on from DOS to Windows. Then I > decided to take Bill Gates' advise when he says, "Windows 98 or better," > so I went way better, all the way to Linux. > > This is now giving me the impetus to get back into programming. I started > out with my only knowledge of c++ as being it is a compiled language, and > that it is a derivative of c. Not much to start with, but one has to > start somewhere. > > I went out and bought a book on C++ programming, _C++ for Dummies_. That > is where my problems started. I can't seem to do anything right with it. > > Not having the ability to run the GNU compiler that came on the disk with > the book, I have to use the GNU compiler that came built into my Linux, > gcc. I copied the first program out of the book as follows: > > // Program to convert temperature from Celsius degree > // units into Fahrenheit degree units: > // Fahrenheit = Celsius * (212-32)/100 + 32 > // > #include <stdio.h> > #include <iostream.h> > > int main(int nNumberofArgs, char* pszArgs[]) > { > // enter the temperature in Celsius > int celsius; > cout << "Enter the temperature in Celsius:"; > cin >> celsius; > > // calculate conversion factor for Celsius > // to Fahrenheit > int factor; > factor = 212 - 32; > > // use conversion factor to convert Celsius > // into Fahrenheit values > int fahrenheit; > fahrenheit = factor * celsius/100 + 32; > > // output the results > cout << "Fahrenheit value is:"; > cout << fahrenheit; > > return 0; > } > > However, when I went to compile it, instead of getting a compiled program, > I got the following mess of error messages: > > [andy(a)localhost C++Lessons]$ gcc conversion.cpp > In file included from > /usr/lib/gcc/i586-mandriva-linux-gnu/4.0.1/../../../../inc > lude/c++/4.0.1/backward/iostream.h:31, > from conversion.cpp:6: > /usr/lib/gcc/i586-mandriva-linux-gnu/4.0.1/../../../../include/c++/4.0.1/backwar > d/backward_warning.h:32:2: warning: #warning This file includes at least > one dep recated 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> h eader for the <X.h> header for C++ includes, or > <iostream> instead of the deprec ated header <iostream.h>. To disable this > warning use -Wno-deprecated. /home/andy/tmp/ccN6G3ui.o: In function > `main': conversion.cpp:(.text+0x25): undefined reference to `std::cout' > conversion.cpp:(.text+0x2a): undefined reference to > `std::basic_ostream<char, st > d::char_traits<char> >& std::operator<< > <std::char_traits<char> >(std::basic_ost > ream<char, std::char_traits<char> >>&, char const*)' conversion.cpp:(.text+0x39): undefined reference to > `std::cin' conversion.cpp:(.text+0x3e): undefined reference to > `std::basic_istream<char, st > d::char_traits<char> >::operator>>(int&)' > conversion.cpp:(.text+0x7e): undefined reference to `std::cout' > conversion.cpp:(.text+0x83): undefined reference to > `std::basic_ostream<char, st > d::char_traits<char> >& std::operator<< > <std::char_traits<char> >(std::basic_ost > ream<char, std::char_traits<char> >>&, char const*)' conversion.cpp:(.text+0x91): undefined reference to > `std::cout' conversion.cpp:(.text+0x96): undefined reference to > `std::basic_ostream<char, st > d::char_traits<char> >::operator<<(int)' > /home/andy/tmp/ccN6G3ui.o: In function `__tcf_0': > conversion.cpp:(.text+0xb3): undefined reference to > `std::ios_base::Init::~Init( > )' /home/andy/tmp/ccN6G3ui.o: In function > `__static_initialization_and_destruction_ > 0(int, int)': > conversion.cpp:(.text+0xe0): undefined reference to > `std::ios_base::Init::Init() > ' /home/andy/tmp/ccN6G3ui.o:(.eh_frame+0x11): > undefined reference to `__gxx_person > ality_v0' collect2: ld returned 1 exit > status > [andy(a)localhost C++Lessons]$ > > YUK!!!!!!!! > > In trying to make heads or tails out of that mess of error messages, I > changed iostream.h to iostream and that reduced my error messages down to > the following: > > [andy(a)localhost C++Lessons]$ gcc conversion.cpp > conversion.cpp: In function 'int main(int, char**)': > conversion.cpp:12: error: 'cout' was not declared in this scope > conversion.cpp:13: error: 'cin' was not declared in this scope > [andy(a)localhost C++Lessons]$ > > I see nothing in the %^*$*(&% book to give me a clue as to what all this > means. I hope I don't have the same problem with the next zillion > programs. Newbie needs help. What am I doing wrong? > > Is this any way to learn c++??????????? > > -- > Andy Rugg > The Cheerful Pickle You need to get a newer book. But to fix your last errors, every where in your program you have cout, change it to std::cout, where you have cin, change it to std::cin. Then it'll be fine.
From: Cheerful Pickle on 15 Feb 2006 12:19 On Wed, 15 Feb 2006 06:28:59 -0800, Jim Langston wrote: > You need to get a newer book. But to fix your last errors, every where > in your program you have cout, change it to std::cout, where you have > cin, change it to std::cin. > > Then it'll be fine. Did that with the following results (say, what???): [andy(a)localhost C++Lessons]$ gcc conversion.cpp /home/andy/tmp/ccVdmJ5u.o: In function `main': conversion.cpp:(.text+0x25): undefined reference to `std::cout' conversion.cpp:(.text+0x2a): undefined reference to `std::basic_ost ream<char, std::char_traits<char> >& std::operator<< <std::char_tra its<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' conversion.cpp:(.text+0x39): undefined reference to `std::cin' conversion.cpp:(.text+0x3e): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)' conversion.cpp:(.text+0x7e): undefined reference to `std::cout' conversion.cpp:(.text+0x83): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_tra its<char> >(std::basic_ostream<char, std::char_traits<char> >&, cha r const*)' conversion.cpp:(.text+0x91): undefined reference to `std::cout' conversion.cpp:(.text+0x96): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)' /home/andy/tmp/ccVdmJ5u.o: In function `__tcf_0': conversion.cpp:(.text+0xb3): undefined reference to `std::ios_base::Init::~Init()' /home/andy/tmp/ccVdmJ5u.o: In function `__static_initialization_and_destruction_0(int, int)': conversion.cpp:(.text+0xe0): undefined reference to `std::ios_base::Init::Init()' /home/andy/tmp/ccVdmJ5u.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status [andy(a)localhost C++Lessons]$ That took me from three errors to a zillion. Oh, well, back to the old drawing board. Thanks, anyway. -- Andy Rugg The Cheerful Pickle
From: Cheerful Pickle on 15 Feb 2006 12:36
On Wed, 15 Feb 2006 06:15:51 -0800, osmium wrote: > I used cut an paste and made four changes and your program worked. It > even produces the right answers! > > o include lines - two places > o using namespace std > o a system ("pause"); statement so I could see the result. A peculiarity > of my compiler, you shoudl not need that or any equivalent. Accordingly I > have commented it out. > ------------------- > // #include <stdio.h> > // #include <iostream.h> > #include <cstdio> > #include <iostream> > > int main(int nNumberofArgs, char* pszArgs[]) > { > using namespace std; > // enter the temperature in Celsius > int celsius; > cout << "Enter the temperature in Celsius:"; cin >> celsius; > > // calculate conversion factor for Celsius // to Fahrenheit > int factor; > factor = 212 - 32; > > // use conversion factor to convert Celsius // into Fahrenheit values > int fahrenheit; > fahrenheit = factor * celsius/100 + 32; > > // output the results > cout << "Fahrenheit value is:"; > cout << fahrenheit; > //system("pause"); > > return 0; > } Thanks, I copied and pasted it into a new file, but, unfortunately, it did not work for me, as the following testifies: [andy(a)localhost C++Lessons]$ gcc newsconversion.cpp /home/andy/tmp/cch5C2Ja.o: In function `main': newsconversion.cpp:(.text+0x25): undefined reference to `std::cout' newsconversion.cpp:(.text+0x2a): 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*)' newsconversion.cpp:(.text+0x39): undefined reference to `std::cin' newsconversion.cpp:(.text+0x3e): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)' newsconversion.cpp:(.text+0x7e): undefined reference to `std::cout' newsconversion.cpp:(.text+0x83): 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*)' newsconversion.cpp:(.text+0x91): undefined reference to `std::cout' newsconversion.cpp:(.text+0x96): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)' /home/andy/tmp/cch5C2Ja.o: In function `__tcf_0': newsconversion.cpp:(.text+0xb3): undefined reference to `std::ios_base::Init::~Init()' /home/andy/tmp/cch5C2Ja.o: In function `__static_initialization_and_destruction_0(int, int)': newsconversion.cpp:(.text+0xe0): undefined reference to `std::ios_base::Init::Init()' /home/andy/tmp/cch5C2Ja.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status [andy(a)localhost C++Lessons]$ -- Andy Rugg The Cheerful Pickle |