ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have decided to get back into C++. I am finding things pretty easy, as I took the dive into learning PHP a little while back. I dont know that much... variables, if's, while's... tell me what you think, and how I can improve it.
Are you by any chance using something like Borland Turbo C++, where the output window closes as soon as the program has run? In which case, I'd use getch(); or something like cin << c (where c is a char).
That will work even on operating systems that don't have a PAUSE command on the path.
well, the program you wrote is in C not C++.
but that's a good start.
in C++ the concept is quite different (object oriented) rather than C (procedural.)
you might want to learn first the concepts of Object Oriented Programming (OOP) using a book, ebook, or just googling for it, unless you want to work in C in which case forget what i said
well, the program you wrote is in C not C++.
but that's a good start.
in C++ the concept is quite different (object oriented) rather than C (procedural.)
you might want to learn first the concepts of Object Oriented Programming (OOP) using a book, ebook, or just googling for it, unless you want to work in C in which case forget what i said
Since when did the C standard implement with the iostream library. The program is C++. Most people just starting out on any OO language write basic programs which do not encapsulate OO principles to start with. You have to learn to walk before you run.
Hey,
I don't want to run into fights or arguements here,
but what i meant is that the program he wrote is in C.
the fact that he used a C++ library is a different story.
but the code he himself wrote was standard C.
One other minor comment... iostream.h and all the standard C/C++ headers with the .h extension are deprecated in the ANSI/ISO C++ spec. Instead, you should include the file w/o the .h, which will put everything from that header into the std namespace. Standard C files should be included by pre-pending a c, and dropping the .h. (e.g. #include <iostream.h> becomes #include <iostream>, #include <stdio.h> becomes #include <cstdio>, etc.)
By doing this you then need to be sure to use the standard C++ stuff from the std namespace. The easiest way to do this is to simply add the following line to your code someplace after your #includes:
using namespace std;
Or you can change all your couts to std::cout, cins to std::cin, etc.
bash-2.05b$ gcc lq.c -o lq
lq.c:1:22: iostream.h: No such file or directory
lq.c: In function `main':
lq.c:8: error: `cout' undeclared (first use in this function)
lq.c:8: error: (Each undeclared identifier is reported only once
lq.c:8: error: for each function it appears in.)
lq.c:10: error: `cin' undeclared (first use in this function)
lq.c:5: warning: return type of `main' is not `int'
It is not C. At all. (I added char c; and cin << c; in the source code and removed the system("PAUSE"); bit in the code i tried to compile as C).
I don't understand how it is C. If a program written in java doesnt make use of its OO properties, what is it? What about perl or php? He wrote it as C++, he used C++ libraries, he compiled it with a C++ compiler. So it's C++, as far as i'm concerned.
MrBlack: A cool game to write in a new language to play with strings etc is hangman, i had a bit of fun doing that one . Give it a go
First, I can't compile it using g++, so I suppose portability is the first thing to fix. Also, I would ditch the Pause command, since not all systems can do that. Try using the ncurses library and the getch() function.
DanTheKiwi mentioned Hangman as a cool game to write in C++. Something that would probably prove helpful is the ncurses library I mentioned earlier. It probably came with whatever compiler you have, and you can find information on it here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.