Originally Posted by
aamirbwppk
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;
}