C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-04-2002, 01:57 PM   #1
Unregistered
Guest
 
Posts: n/a
Question cin/cout under Linux...

I have been a windows user for a long time (far too long), and learned c++ using borland C++Builder 5. Although i am quite proficient at programming in that environment, i recently decided to try out linux (first Slackware 7, now Redhat 7.1).

Obviously, one of the things i tried was to write a program ("hello world..." you know the variety), just to get to know the way of doing things under linux better. To my surprise, i couldn't get cout and cin to work! (i /did/ #include <iostream>;) So I used gets() and puts() instead.

Now, i have read about cin and cout, but never had to use them, because of all the other nice features that builder has, like editboxes and so forth. Can someone please, oh very please show me sample "hello world" code, using cin and/or cout that works in linux?



As a side issue, how do I get rid of the GUI in redhat 7.1 - i want to work in a pure console (not an emulator)? The GUI is nice and dandy, but when i am working in linux, i really don't want to be reminded of windows!
  Reply With Quote
Old 06-04-2002, 02:09 PM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,693
Did you do these two things as well

1. Put the source code in a .cpp file - eg. prog.cpp
2. use the c++ compiler, not the c compiler - eg. g++ prog.cpp

The result (if all is well) should be a file called a.out, which you run by typing
./a.out
Salem is offline   Reply With Quote
Old 06-04-2002, 05:14 PM   #3
Registered User
 
stautze's Avatar
 
Join Date: Apr 2002
Posts: 195
>As a side issue, how do I get rid of the GUI in redhat 7.1


http://www.cprogramming.com/cboard/s...threadid=18995
__________________
'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition
stautze is offline   Reply With Quote
Old 06-04-2002, 05:22 PM   #4
Unregistered
Guest
 
Posts: n/a
also,

you must bring elements cin and cout into scope from the std namespace with the using keyword (when you are using <iostream> instead of the depreciated <iostream.h>) that's just standard, it's not linux specific, although it's compiler specific...

Code:
#include <iostream>

using std::cout;

int main ()
{
    cout << "Hello, world!" << endl;
    return 0;
}
you can always access a console login with ctrl+alt+F1 through ctrl+alt+F6...alt+ F7 to get back to X....
  Reply With Quote
Old 06-05-2002, 02:23 PM   #5
Unregistered
Guest
 
Posts: n/a
thanx alot, i will try that tonight.
  Reply With Quote
Old 06-05-2002, 08:19 PM   #6
Registered User
 
stautze's Avatar
 
Join Date: Apr 2002
Posts: 195
>you can always access a console login with ctrl+alt+F1 through ctrl+alt+F6...alt+ F7 to get back to X....

Just remember your xserver it still running.
__________________
'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition
stautze is offline   Reply With Quote
Old 06-20-2002, 06:06 PM   #7
Unregistered
Guest
 
Posts: n/a
Smile

Just include "stdio.h"
Then you can use all the "C" io functions
eg. printf etc..etc..
  Reply With Quote
Old 07-09-2002, 03:10 PM   #8
Registered User
 
Join Date: Jun 2002
Posts: 106
#include <iostream>
using namespace std;

int main()
{

cout <<"hello world"<<endl;
exit(0);
}

save this as example.cpp

in the console

type

g++ -o executable_name example.cpp
and compıle it
the run
__________________
C++ Makes you Feel Better

"Gravity connot be held reponsible for people falling in love"--Albert Einstein
onurak is offline   Reply With Quote
Old 07-09-2002, 06:51 PM   #9
Registered User
 
Join Date: Sep 2001
Location: Australia
Posts: 212
Quote:
onurak wrote
Code:
 #include <iostream> 
using namespace std; 

int main() 
{ 

cout <<"hello world"<<endl; 
exit(0); 
}
Did you even test this, the exit function requires <cstdlib> to work.
kwigibo is offline   Reply With Quote
Old 07-25-2002, 09:53 AM   #10
Registered User
 
Join Date: Jul 2002
Posts: 29
Huh, this is advanced stuff

Erh, guys... This is a "Hello world" program... it shouldn't really be any trouble. Well, just so you don't flame me:

#include <iostream.h>

int main(void) {

cout << "Hello world" << endl;

return 0;

}

Hehe, wouldn't wonder if that doesn't work either, I never use cout... printf kicks. Ass.
__________________
I like traffic lights. I like traffic lights. I like traffic lights, but only when they're green.
Skarr is offline   Reply With Quote
Old 07-26-2002, 05:06 AM   #11
Registered User
 
Join Date: Jun 2002
Posts: 106
exit function works well with iostream liblary no problem i always use exit() function with iostream liblary
__________________
C++ Makes you Feel Better

"Gravity connot be held reponsible for people falling in love"--Albert Einstein
onurak is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Thinking of upgrading to linux... Yarin General Discussions 37 07-24-2009 11:40 AM
Wireless Network Linux & C Testbed james457 Networking/Device Communication 3 06-11-2009 11:03 AM
Dabbling with Linux. Hunter2 Tech Board 21 04-21-2005 04:17 PM
installing linux for the first time Micko Tech Board 9 12-06-2004 05:15 AM


All times are GMT -6. The time now is 07:39 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22