how to get a string as input ?
-
Here's what i have tried.
#include
#include
#define MAX 100
using namespace std;int m=0;
class Names{
char name[5][30];
//static int m;
public:
//Names(){m++;}
void getdata(){
//int temp = m;
//string s;
cout<<"Entre name :\t";
cin.ignore(1000, '\n');
cin>>name[m];
//getline(cin, name[m]);
//strcpy(name[m],s);
m++;
}
void display(void){
for(int i=0; ii tried getline(), but it was giving error. How do i take a string as a input ?
-
Here's what i have tried.
#include
#include
#define MAX 100
using namespace std;int m=0;
class Names{
char name[5][30];
//static int m;
public:
//Names(){m++;}
void getdata(){
//int temp = m;
//string s;
cout<<"Entre name :\t";
cin.ignore(1000, '\n');
cin>>name[m];
//getline(cin, name[m]);
//strcpy(name[m],s);
m++;
}
void display(void){
for(int i=0; ii tried getline(), but it was giving error. How do i take a string as a input ?
Please test it and let me know whether it solved your requirement.
#include
#include#define MAX 100
using namespace std;class Names {
string name[3];
//static int m;
public:
//Names(){m++;}
void getdata()
{
for (int i = 0; i < 3; i++)
{
cout << "Enter Names:" << endl;
getline(cin,name[i]);
}
}
void display(void) {
for (int i = 0; i<3; i++) {
cout << name[i] << endl;
}
}
};void main()
{
Names n;
n.getdata();
n.display();
getchar();
} -
Here's what i have tried.
#include
#include
#define MAX 100
using namespace std;int m=0;
class Names{
char name[5][30];
//static int m;
public:
//Names(){m++;}
void getdata(){
//int temp = m;
//string s;
cout<<"Entre name :\t";
cin.ignore(1000, '\n');
cin>>name[m];
//getline(cin, name[m]);
//strcpy(name[m],s);
m++;
}
void display(void){
for(int i=0; ii tried getline(), but it was giving error. How do i take a string as a input ?
Tarun Jha wrote:
i tried getline(), but it was giving error.
Can you make your font size larger? I cannot see the error from here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Tarun Jha wrote:
i tried getline(), but it was giving error.
Can you make your font size larger? I cannot see the error from here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles