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.
Distribution: Fedora Core 3, Damn Small Linux 0.93, Ubuntu 5.10, Mandrake 10.1 Official, Linspire 4.5, SuSE 10.0
Posts: 77
Rep:
C++ programming
I recently transeferred to F3 and am a total noob. BUt i found out you could program c++ in it. My questions is in Windows u can include the header stdio.h and use the command system("PAUSE"), but in linux it doesnt recognize it. Is there any way u could download an upgrade or is there a substitue for that? And after compiling a program i double click on it and it does nothing instead to run it i have to open terminal and type in its location and its name, is it supposed to run only in that way or is it supposed to open when u double click it?
Most likely, the program does run when you double click it. And if you're programming in C++, you shouldn't be using stdio.h as a header file. Other than that, what errors do you get?
What does command("PAUSE") do? If you want your process to sleep for a # of seconds, use sleep (man -S 3 sleep), pause in unix suspends the process until it gets a signal.
I believe stdio.h is a C header file. This is why you shouldn't be using it. It also appears to contain some windows specific functions
I believe a standard work around for this is to place a cin where you wish for your program to pause, as the cin function will have the effect of making the program wait until there is further user input.
You are supposed to have to run non-gui programs from the console if you wish to see their output. However, some window managers (KDE, etc.) I believe have an option where you can right click on the executable, select properties (or something to that extent) and set it so that it will open in a terminal. This should have the same effect as opening a new 'window' with your program executing inside of it.
The reason system("PAUSE") doesn't work in Linux is that it is trying to execute the PAUSE command, which is a DOS command that prints "Press any key to continue..." and then waits for a key to be pressed. This is not a linux shell command, so it won't work in linux. Probably the easiest replacement would be to do something like:
Code:
string tempInput;
cout << "Press enter to continue..." << endl;
getline(cin, tempInput);
Note that if you have done any other things with cin, you may have to do getline twice or use cin.ignore, because using "cin >> somevariable" generally leaves the line feed in the input buffer, so a single getline will read that and return right away...
There are other ways to get a "Press any key..." type functionality, but it's a bit more work than just a couple lines of code. Search the boards here for more info and you will find a few routines to do that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.