Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 13th, 2004, 11:31 PM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Gubber
Default more getline problmes

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
    string words, dummy;
    int borb;

    cout << "Enter Input: ";
    getline(cin, words);
    cin >> borb;

    cout << words << endl;

    return 0;
}

When I add the cin after the getline, it gives be problems, i have to type in more stuff and hit enter again before it ontinues on, any ideas?

Ian
Reply With Quote
  #2 (permalink)  
Old July 17th, 2004, 06:16 PM
Tez Tez is offline
Registered User
 
Join Date: Jul 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try the following:

#include <iostream>

using namespace std;

int main()
{
    const int str_len = 80;
    char words[str_len];
    //int borb;

    cout << "Enter Input: ";
    cin.getline(words, str_len, '\n');
    //cin >> borb;

    cout << words << endl;

    return 0;
}

I've commented out the "cin >> borb;" statement as that was your problem - it's requesting another value. The getline() function has already completed all the input but the program is waiting for the next cin statement to be satisfied.

Tez
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
cin.getLine() function skips. Please help! unpopular C++ Programming 3 February 29th, 2008 11:50 AM
C++ Beginner having (the usual?) getline problems Slapworth C++ Programming 2 October 10th, 2004 01:45 PM
cin.getline alfrepa Visual C++ 0 April 14th, 2004 08:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.