Compiler Question

This is a discussion on Compiler Question within the C++ Programming forums, part of the General Programming Boards category; I have a question its more of a curiosity thing really. When I compile the code below and make an ...

  1. #1
    .........
    Join Date
    Nov 2002
    Posts
    303

    Compiler Question

    I have a question its more of a curiosity thing really. When I compile the code below and make an exe the program works differently depending on the compiler I use. Yet the code is exactly the same. Anyone know why?

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() {
    
    	string y;
    
    	getline(cin,y);
    
    	cout << y;
    
    	return 0;
    }
    When I compile that with VC++, it prompts me to enter a value. After I type whatever in and press enter, I have to press Enter once again for the cout statement to work.

    But when compiled in Dev C++ , it works properly and the cout statement executes as soon as I hit enter. Any idea why they work differently if its the same exact code?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    VC++ has a bug in getline that requires you to hit return twice.

    -Prelude
    My best code is written with the delete key.

  3. #3
    .........
    Join Date
    Nov 2002
    Posts
    303
    Thank You !! It was driving me nuts wondering hehe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about compiler copying objects
    By Sharke in forum C++ Programming
    Replies: 3
    Last Post: 06-15-2009, 09:25 AM
  2. gcc compiler question
    By s_ny33 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 08:13 AM
  3. question about bool
    By ssharish2005 in forum C Programming
    Replies: 7
    Last Post: 10-17-2005, 09:18 AM
  4. C/C++ Compiler Question
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 07-09-2002, 03:09 AM
  5. Question: Which Compiler????
    By MaBo in forum C Programming
    Replies: 5
    Last Post: 06-04-2002, 12:57 PM

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