![]() |
| | #1 |
| Guest
Posts: n/a
| 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! |
|
| | #2 |
| and the hat of Jobseeking 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 | |
| | #3 |
| Registered User 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 | |
| | #4 |
| 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;
}
|
|
| | #5 |
| Guest
Posts: n/a
| thanx alot, i will try that tonight. |
|
| | #6 |
| Registered User 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 | |
| | #7 |
| Guest
Posts: n/a
| Just include "stdio.h" Then you can use all the "C" io functions eg. printf etc..etc.. |
|
| | #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 | |
| | #9 | |
| Registered User Join Date: Sep 2001 Location: Australia
Posts: 212
| Quote:
| |
| kwigibo is offline | |
| | #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 | |
| | #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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |