Wrox Programmer Forums
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ 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
 
Old April 14th, 2004, 08:05 PM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default cin.getline

I am trying to use this command, 'cin.getline', in a loop, but it does not work properly; in details, it works the first time the loop is executed; the subsequent times, it is just ignored; now, in all the books I am using ther's no mention of this strange behavior; nor there is anything in the tutorial that comes with the Visual C++ that I have. Could you please help me overcome this problem, and explain to me why is behaving like that, done the fact that in my books, and in the documentation ovf Visual C++ it says that this command does NOT carry any linefeed?
thanks so much for the attention.
I include an example of the code where I have met this problem; but is not the only one time...
// size1.cpp
//

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

int main()
{
    char arr[10][30];
    int a = 0;
    char ind;
    float cont = 0.0f;

    for(a; a < 10; a++)
    {
        cout << "\nenter a word: ";
        cin.getline(arr[a],30, '\n'); // quì non va; e non
        // è la prima volta!!!
        for(int i = 0; i <30; i++)
        {
            cout << arr[a][i];
            if(arr[a][i] == '\0')
            {
                break;
            }
        }
        //getchar();
        cout << "do you want to enter another one?";
        cout << "\n(Enter 0 to end, 1 to continue): ";
        cin >> ind ;
        if(ind == '0')
        {
            break;
        }
        else
        {
            cout << " " << endl;
        }
    }
    cont = sizeof(arr)/sizeof(arr[0]);
    cout << cont;
        cout << endl;
    return 0;
}





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
Determining Data type with CIN Bourne C++ Programming 2 March 23rd, 2007 05:40 PM
Problems with cin eye_of_telescope C++ Programming 1 March 17th, 2005 10:41 AM
C++ Beginner having (the usual?) getline problems Slapworth C++ Programming 2 October 10th, 2004 01:45 PM
more getline problmes Gubber C++ Programming 1 July 17th, 2004 06:16 PM





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