LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-27-2005, 04:18 PM   #1
aznboi12321
Member
 
Registered: Feb 2005
Location: Sharon,MA
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: Reputation: 15
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?
 
Old 02-27-2005, 08:41 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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?
 
Old 02-27-2005, 08:56 PM   #3
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
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.
 
Old 02-27-2005, 08:56 PM   #4
Dodgeram01
Member
 
Registered: Jun 2003
Distribution: Gentoo and Ubuntu
Posts: 95

Rep: Reputation: 15
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.
 
Old 02-27-2005, 09:17 PM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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.

Last edited by deiussum; 02-27-2005 at 09:23 PM.
 
Old 03-01-2005, 06:15 AM   #6
aznboi12321
Member
 
Registered: Feb 2005
Location: Sharon,MA
Distribution: Fedora Core 3, Damn Small Linux 0.93, Ubuntu 5.10, Mandrake 10.1 Official, Linspire 4.5, SuSE 10.0
Posts: 77

Original Poster
Rep: Reputation: 15
is cin.getline() and getline(cin, ) the same thing
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
which programming language is used to do tcp/ip programming?? gajaykrishnan Linux - Networking 9 12-21-2012 05:16 AM
im new to programming but..... boxerboy Programming 6 08-26-2005 06:17 AM
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM
C programming oranj Linux - Networking 1 12-07-2004 12:40 AM
Qt Programming... jinksys Programming 1 08-06-2003 04:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration