Simple Error = Difficult Problem

This is a discussion on Simple Error = Difficult Problem within the C++ Programming forums, part of the General Programming Boards category; I have a new compiler along my Dev C++ it is called Mircrosoft Visual Beta 2005. It looks sl much ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475

    Simple Error = Difficult Problem

    I have a new compiler along my Dev C++ it is called Mircrosoft Visual Beta 2005. It looks sl much more professional too!!

    Anyway, This is my first working program, but when I debugged and ran it, it worked ok, but I got a unfamiluar warning up it said:

    " 'getch' was declared deprecated :: see declaration of 'getch'

    I do not understand what the warning is saying, as I delcared getch as part of conio.h

    I use getch so I do not have to use system("pause");

    here is the code:

    Code:
    #include "stdafx.h" // this header is for ALL USE
    #include <iostream>
    #include <string>
    #include <conio.h>
    
    using namespace std;
    
    string myname;
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	cout << "What is your name?" << endl;
    	cout << "\n\n";
    	cout << "My name is ";
    	cin >> myname;
    	cout << "So your name is " << myname;
    	cout << "\n\n";
    	getch();
    	return 0;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    > I do not understand what the warning is saying, as I delcared getch as part of conio.h
    It's basically telling you that all the stuff in conio.h is now very old, and that it's going to disappear for good at some future point in time.

    It will work for now, but you should be taking this opportunity to look for alternative ways of solving the problem while you can (rather than later when it all stops working all of a sudden).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    " 'getch' was declared deprecated :: see declaration of 'getch'

    I do not understand what the warning is saying, as I delcared getch as part of conio.h
    In a conversational way, the compiler is trying to tell you that getch() is deprecated. Deprecated means don't use it.

  4. #4
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    cin.sync();
    cin.get();

    You are programming in C++, right (you posted on a C++ board), so use C++ IO.

    In any case, getchar() is part of <stdio.h>/<cstdio>.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  5. #5
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    212
    I've heard that sync() is ambigulous. Some one suggested that we should use ignore()

  6. #6
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    For maximum portability, perhaps. I have used this on Solaris, Windows and Linux without any problem.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  7. #7
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    ignore is not for pausing, i think...
    cin.sync();
    cin.get();

    You are programming in C++, right (you posted on a C++ board), so use C++ IO.

    In any case, getchar() is part of <stdio.h>/<cstdio>.
    if cin from iostream is c++ i/o why isn't getch();?
    I'm a beginer and in almost all the books i've read, they use conio--getch(), even in books that follow strict standard c++.

  8. #8
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    conio is NOT part of any standard (C or C++), so whatever they blather on the cover about standards is bull........ if they use it in their book.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  9. #9
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Here is the definition of deprecated from dictionary.com:

    Quote Originally Posted by dictionary.com
    deprecated

    adj. Said of a program or feature that is
    considered obsolescent and in the process of being phased out,
    usually in favor of a specified replacement.
    Deprecated features
    can, unfortunately, linger on for many years. This term appears
    with distressing frequency in standards documents when the
    committees writing the documents realize that large amounts of
    extant (and presumably happily working) code depend on the
    feature(s) that have passed out of favor. See also dusty deck.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Ok, I have tried all the above, and the only one that seems to work is the one I hate using which is system("pause");.

    The strange thing is, on my other compiler, DevC++, getch() works ok without any errors or warnings, maybe it is because I have a more updated compiler now, I know microsoft compilers are some of the best around (well, the up-to-date ones anyway lol!)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple File I/O problem
    By Ignited in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2006, 09:49 AM
  2. Fairly simple problem
    By fatdunky in forum C Programming
    Replies: 1
    Last Post: 11-14-2005, 10:34 PM
  3. Simple Variable Problem
    By Cthulhu in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2005, 03:07 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. Simple problem, yet difficult for n00b like me :-/
    By 1943 in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 09:05 AM

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