C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-26-2009, 10:43 PM   #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
aamirbwppk is offline   Reply With Quote
Old 10-26-2009, 10:45 PM   #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
aamirbwppk is offline   Reply With Quote
Old 10-27-2009, 06:28 AM   #3
Registered User
 
hk_mp5kpdw's Avatar
 
Join Date: Jan 2002
Location: Northern Virginia/Washington DC Metropolitan Area
Posts: 2,870
7.5 year bump = bad.
__________________
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
--Charles Babbage, 1792-1871

09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
hk_mp5kpdw is offline   Reply With Quote
Old 10-27-2009, 06:58 AM   #4
Registered User
 
Join Date: Oct 2009
Location: While(1)
Posts: 368
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;
}
RockyMarrone is offline   Reply With Quote
Old 10-27-2009, 08:45 AM   #5
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 11,339
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
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A question related to strcmp meili100 C++ Programming 6 07-07-2007 02:51 PM
WS_POPUP, continuation of old problem blurrymadness Windows Programming 1 04-20-2007 06:54 PM
Laptop Problem Boomba Tech Board 1 03-07-2006 06:24 PM
Sorting problem.. well actually more of a string problem fatdunky C Programming 5 11-07-2005 11:34 PM
half ADT (nested struct) problem... CyC|OpS C Programming 1 10-26-2002 08:37 AM


All times are GMT -6. The time now is 06:47 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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