Am I on drugs ??

This is a discussion on Am I on drugs ?? within the C++ Programming forums, part of the General Programming Boards category; as simple as this Code: #include<iostream> #include<string> using namespace std ; int main () { string str; cout << "Please ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    34

    Question Am I on drugs ??

    as simple as this

    Code:
    #include<iostream>
    #include<string>
    
    using namespace std ;
    
    
    int main () 
    {
      string str;
      cout << "Please enter full name: ";
      getline (cin,str);
      cout << "Thank you, " << str << ".\n";
      return 0;
    }
    after entering the following : "Goerge Bush" I hit ENTER key...which should then display
    Code:
    Thank you, George Bush
    right ??Well it doesnt..what happens is following:

    after entering George Bush and hitting the "ENTER" key the cursor just jumps to the next line WHERE I AM ABLE TO ENTER ANOTHER FULL NAME.Upon hitting ENTER the second time the name "George Bush" is displayed (however not the second name ;not that i want to enter a second person)

    How is it that i get to input anything after hitting ENTER the first time...this never happened before
    I am in love with c++...Hence i broke off with my girl

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Too obvious -_-.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    34
    Lol...o mighty lords of c++ then pls do enlighten me in my quest to be the master of c++

    Seriously...any help...i could just live with hitting ENTER twice after the input but i wanna know why it is being so

    Ohh and sorry that the title doesnt describe the problem at all...which is a no no according to the posting rules...will be carefull next time
    Last edited by roalme00; 01-10-2008 at 09:13 AM.
    I am in love with c++...Hence i broke off with my girl

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    I thought I knew what indigo0086 was getting at, but a quick check shows that getline() for std::string has a default argument of '\n' for its third parameter, so your code should work. I checked by compiling with MSVC8 and the MinGW port of g++ 3.4.5 and could not reproduce your problem.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    34
    Exactly...thats why the title "Am I on Drugs"

    I never had the problem using Visual Studio 2005 or.NET

    However when using Visual Studio 6.0 the problem is rampant....

    I did some more googling on it and came across this...

    Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. This problem was corrected in Microsoft Visual C++ .NET.

    this is the example code on the Microsoft site to illustrate the bug..

    Code:
    The following sample program demonstrates the bug:
    
    //test.cpp
    //Compiler options : /GX
    #include <string>
    #include <iostream>
    int main () {
    	std::string s,s2;
    	std::getline(std::cin,s);
    	std::getline(std::cin,s2);
    	std::cout << s <<'\t'<< s2 << std::endl;
    	return 0;
    }
    Actual Results:
    Hello<Enter Key>
    World<Enter Key>
    <Enter Key>
    Hello World

    Expected Results:
    Hello<Enter Key>
    World<Enter Key>
    Hello World

    link to the site : http://support.microsoft.com/?scid=k...0015&x=15&y=16

    what a pain...
    I am in love with c++...Hence i broke off with my girl

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    34
    Sorry didnt see that Tonto had already answered it and given the link

    Thanks again all

    lol i got this 6.0 compiler so i could learn MFC since all the online tutorials for MFC are based on VS 6.0.....

    NVM i will just hit ENTER twice :P
    I am in love with c++...Hence i broke off with my girl

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Sigh, so it was the old getline() bug. I suggest changing compiler. Why must you use MSVC6 when you have MSVC8?

    EDIT:
    NVM i will just hit ENTER twice
    If I remember correctly there is a fix that could be applied.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I wasn't mocking you, roalme. It's just your program input and thread title screamed a pretty clever joke. I thought you put it there intentionally.

  10. #10
    The larch
    Join Date
    May 2006
    Posts
    3,573
    The fix is in the page OP linked.

    But from what I have heard, you are going to have more "high" moments with that compiler.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drugs and schools
    By InvariantLoop in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-27-2004, 08:37 PM
  2. Drugs for programmers
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 76
    Last Post: 11-04-2002, 04:20 AM
  3. Drugs, sex, freindship, and suside.
    By Sentaku senshi in forum A Brief History of Cprogramming.com
    Replies: 55
    Last Post: 08-06-2002, 02:28 AM
  4. Have you ever experimented with illegal drugs?
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 96
    Last Post: 03-11-2002, 08:06 PM
  5. Don't do drugs...
    By Hillbillie in forum A Brief History of Cprogramming.com
    Replies: 44
    Last Post: 12-30-2001, 12:32 AM

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