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.
C++ is not the best language for a beginner to start off with (try Java or Python if you must learn an OOP). And if you want to learn about character arrays, a string object isn't the most educational way to do it.
You could always use your original example but use <stdio.h> functions rather than <iostream> functions.
Code:
$ cat ask.c
#include <stdio.h>
int main () {
char ask[]= "Enter your first name: ";
char answer[]= "So your name is ";
char name[100];
printf("%s", ask);
scanf("%s", name);
printf("%s%s.\n",answer,name);
}
$ gcc -o ask ask.c
$ ./ask
Enter your first name: Johnny
So your name is Johnny.
$
Unfortunately gcc has 2 different meanings, which is quite annoying. First: gcc stands for gnu compiler collection and (how to say) it is (more or less) a language-independent engine (to make executables from source code).
Furthemore gcc itself is one of the tools within gcc, the compiler collection, especially that is the gnu version of the good old c compiler.
If you want to use gcc (the compiler collection) you need to install the engine itself - which are the linker, the preprocessor, debugger among the lot of other goodies) and the language specific toolset too (like c, c++, fortran ... and/or whatever compiler you need).
The name of the c++ compiler is g++
Unfortunately gcc has 2 different meanings, which is quite annoying. First: gcc stands for gnu compiler collection and (how to say) it is (more or less) a language-independent engine (to make executables from source code).
Furthemore gcc itself is one of the tools within gcc, the compiler collection, especially that is the gnu version of the good old c compiler.
If you want to use gcc (the compiler collection) you need to install the engine itself - which are the linker, the preprocessor, debugger among the lot of other goodies) and the language specific toolset too (like c, c++, fortran ... and/or whatever compiler you need).
The name of the c++ compiler is g++
yeah im pretty sure that all came with installing code::blocks, but i'm also curious about how people would use gedit and notepad and then just compile code straight from that
yeah im pretty sure that all came with installing code::blocks, but i'm also curious about how people would use gedit and notepad and then just compile code straight from that
What do you mean how? The same way you've done at the start of this thread, except without mixing C and C++. If you want to use iostream, cin, cout, etc., that's C++, which means your code should end in .cpp and you should compile it with g++. If you want to use C, then the code should end in .c and you should use printf, etc.
in general gedit and notepad are not really used to write code, there are much better editors available exactly for that. Using one of those editors you will be able to "just compile code straight from that". Those are: vi (or vim), emacs, eclipse and a huge amount of other tools. They called IDE. (in MS Windows there is an editor called notepad++ which is also very good, because that is much more than a simple notepad).
So return back to your question: developers do not use gedit or notepad, but you can start using those and also write a makefile to compile and build your code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.