LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-28-2003, 04:26 AM   #1
james.farrow
Member
 
Registered: Mar 2003
Location: UK Darlington
Distribution: Fedora Freebsd Centos
Posts: 296

Rep: Reputation: 31
C++ and very confused


1stly I've searched the forum and read relevant post and am still none the wiser!!! I am currently trying to learn C++, and at college we use the M$ compiler and at home I have Bloodshed and Redhat 9. A task was to use buffered and unbuffered input and output. The functions given with a brief explanation were:- _kbhit , ungetch , getch , getche , putch , and cputs to start with.

//Example of _kbhit

#include <stdio.h>
#include <conio.h>

int main()
{
cputs ("Hit any character ket when ready\n");
while (! _kbhit())
; //inifinite loop til a key pressed
cputs("The key pressed was ");
putch(getch());
putch('\n');
return 0;
}

The above works fine on bloodshed and M$ but gives numerous errors when compiling with g++, any help will be greatly aprecited!!

Thanx in advance......
 
Old 11-28-2003, 05:21 AM   #2
mr_segfault
Member
 
Registered: Oct 2003
Location: Australia
Distribution: Redhat 9
Posts: 95

Rep: Reputation: 15
OK, the answer is rather simple (once you know the answer )

The funtions _kbhit , ungetch, etc, are provided with the conio library. This is specific dos, (although may have been ported to other platforms (?)).

Under linux the common replacement in the curses/ncurses libraries

Some links

http://dickey.his.com/ncurses/ncurses.faq.html

If you must use conio functions (I wouldn't) I found this on google. http://www.ibiblio.org/linsearch/lsm...onio-1.02.html

If you are learning C++, you are probably better off to use the iostream libraries.

Some reference: http://www.roguewave.com/support/doc...epro/index.cfm

Cheers..

Last edited by mr_segfault; 11-28-2003 at 05:25 AM.
 
Old 11-28-2003, 05:26 AM   #3
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
Hi,
First thing that you should know is that C on Linux/*nix is different than C on M$. Programs written for M$ cannot be so easily ported on the Linux/*nix and vice-versa. So, header files,functions and system calls which you have used on M$ may or maynot be available on Linux/*nix(like conio.h, kbhit() etc). So, the best way which I can think of is to get hold of a good book/docs which teaches c/c++ on linux. This will be much better I suppose. Hope this helps
 
Old 11-28-2003, 05:41 AM   #4
mr_segfault
Member
 
Registered: Oct 2003
Location: Australia
Distribution: Redhat 9
Posts: 95

Rep: Reputation: 15
The best thing to do is learn the standard to then know what is portable and what is not. Then you can abstract the non portable implementation away from the 'real' code..

Marshall Cline, has a book (the real paper back one, not the online lite version) covers most of the important aspects of using the C++ standard and I recommend it to all programmers (not only C++ programmers).

C++ FAQ Second Edition



And The C++ Professional Handbook covers the standard to a technically detailed level (down to some specific compiler implementation details). And is another book I would recommend to every C++ programmer.

Cheers
 
Old 11-28-2003, 01:49 PM   #5
ugenn
Member
 
Registered: Apr 2002
Posts: 549

Rep: Reputation: 30
When it comes to C++, the ONE book u must read is The C++ Programming Language by Bjarne Stroustrup.
 
Old 11-28-2003, 01:58 PM   #6
MartinN
Member
 
Registered: Nov 2003
Location: Ronneby, Sweden
Posts: 555

Rep: Reputation: 30
Quote:
Originally posted by ugenn
When it comes to C++, the ONE book u must read is The C++ Programming Language by Bjarne Stroustrup.
Can't disagree more. That is definitely not a book to give someone who's a C++ newbie. I know, cause I've been through that purgatory.

A much better book for beginners would be C++ Primer by Stanley B. Lippman and Josée Lajoie.

That said, Stroustrup's book is a good reference material for one reason -- since Bjarne is C++, if his book says one thing and the compiler disagrees, then the compiler needs to be changed.

Martin
 
  


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
Very confused unkn0wnhacka Linux - General 12 07-20-2005 09:44 AM
Please help, I'm so confused sdat1333 SUSE / openSUSE 4 12-11-2004 09:23 PM
confused FrozenPenquin Linux - Newbie 26 12-09-2003 09:27 AM
so confused... KeTrueno Linux - General 1 09-28-2003 01:45 PM
Confused pilotgi Linux - Newbie 9 04-20-2002 12:06 AM

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

All times are GMT -5. The time now is 06:15 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