Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to get a string as input ?

how to get a string as input ?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tarun Jha
    wrote on last edited by
    #1

    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; i

    i tried getline(), but it was giving error. How do i take a string as a input ?

    S D 2 Replies Last reply
    0
    • T Tarun Jha

      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; i

      i tried getline(), but it was giving error. How do i take a string as a input ?

      S Offline
      S Offline
      Sampath579
      wrote on last edited by
      #2

      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();
      }

      1 Reply Last reply
      0
      • T Tarun Jha

        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; i

        i tried getline(), but it was giving error. How do i take a string as a input ?

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • D David Crow

          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

          T Offline
          T Offline
          Tarun Jha
          wrote on last edited by
          #4

          i will try . and thank you

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups