Problem with using cin.getline() more than once

This is a discussion on Problem with using cin.getline() more than once within the C++ Programming forums, part of the General Programming Boards category; have there any genious one who tell me that what is the main function of [B] cin.getline()[/ B] and what ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Location
    Bahawalpur -> Punjab (Pakistan)
    Posts
    2

    Problem with using cin.getline() more than once

    have there any genious one who tell me that what is the main function of
    [B]cin.getline()[/B] and what happened when we use cin.getline () more than one time there is a problem occur the second one cannot get the string.
    How can i solve this problem ???????????
    Plz tell me immediatly

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    Bahawalpur -> Punjab (Pakistan)
    Posts
    2
    cin.getline()

    --------------------------------------------------------------------------------

    have there any genious one who tell me that what is the main function of
    cin.getline() and what happened when we use cin.getline () more than one time there is a problem occur the second one cannot get the string.
    How can i solve this problem ???????????
    Plz tell me immediatly

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    7.5 year bump = bad.
    "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

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by aamirbwppk View Post
    cin.getline()

    --------------------------------------------------------------------------------

    have there any genious one who tell me that what is the main function of
    cin.getline() and what happened when we use cin.getline () more than one time there is a problem occur the second one cannot get the string.
    How can i solve this problem ???????????
    Plz tell me immediatly
    First of all i think you are here for help not we are hearing your order that ........

    what is this "have there any genious one who tell me"

    First of all you try at your end very hard and if the problem persist for so long then come here

    and the code which you are looking for is this one

    Code:
    #include <iostream>
    
    #define LENGTH 100
    #define EOL    '\n'
    
    int main() {
      char name[LENGTH] = {0};
      while (1) {
        std::cout << "Please enter your name !!!" << std::endl;
        std::cin.getline(name, 100, EOL);
        std::cout << "Welecome " << name << std::endl;
        memset(name, 0, LENGTH);
      }
      return 0;
    }

    Your code which is working at my end with one getline after getline

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    char id[500000];
    char age[3] = {0};
    char fileHandle[]=".txt";
    char* fileName;
    char input[100000];
    
    int main() {
      while (1) {
    
        cout<<"PORTFOLIO EDITOR-FILE CREATION TEST"<<endl;
        cout<<"Basically you type in the id number, it gets used in the creation of a file called that number plus .txt"<<endl;
        cout<<"ENTER ID NUMBER"<<endl;
        cin>>id;
        cout<<"Now give me something to write into the file"<<endl;
    
        cin.ignore();
        cin.getline(input,99990,'\n');
    
        cout << "Please enter your age also !!!" << endl;
        cin.getline(age, 3, '\n');
    
        fileName=strcat(id,fileHandle);
        ofstream fout(fileName);
        fout << age;
        fout << "  ";
        fout << input;
        fout.close();
      }
    
      return 0;
    }

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,452
    This thread was moved to avoid resurrecting: problem with cin.getline().

    aamirbwppk, you can find the information you seek by searching online, e.g., getline. As for your specific problem: you should post the smallest and simplest compilable program that demonstrates the problem instead of resurrecting a thread that may well not be related to your problem.

    RockyMarrone, I am afraid that your assistance may well be in vain. If Waldo2k2 is still having problem with the original topic... something must be seriously wrong
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  4. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM

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