-1

1st of all Im newBee at C++ programming.so please apologize if i make lots of mistake while asking questions.

My problem is:

i create class which contain private variable and Methods like below:

class Records{

private:
    string name;
public:
    string n;

    void setValue(){
          cout << "Enter name" << endl;
          cin >> name;
     }

    void getValue(){
         n = name;
        cout << "Name is: " <<  n << endl;
    }

};
Paul R
  • 208,748
  • 37
  • 389
  • 560

1 Answers1

0

I have run your code on GCC compiler, it's successfully worked. Please, see complete example :

#include <iostream>
using namespace std;

class Records{

        private:
                string name;
        public:
                string n;

                void setValue(){
                        cout << "Enter name" << endl;
                        cin >> name;
                }

                void getValue(){
                        n = name;
                        cout << "Name is: " <<  n << endl;
                }
};

int main()
{
        Records r;
        r.setValue();
        r.getValue();
}
  • Your example is wrong, as you did not `#include `. [See here](http://rextester.com/FUMZ20262) – PaulMcKenzie Jun 28 '16 at 06:36
  • [Please read this](http://stackoverflow.com/questions/9539650/why-does-omission-of-include-string-only-sometimes-cause-compilation-failur) – PaulMcKenzie Jun 28 '16 at 06:42
  • Yes, but it depend on compilers. –  Jun 28 '16 at 06:56
  • And when / if gcc changes the way they organize the headers, then what? If you're using `` then it should be included. Not doing so just leads to bad habits. – PaulMcKenzie Jun 28 '16 at 07:00
  • Please, open tutorial point and open gcc compiler, then copy this code and run it. –  Jun 28 '16 at 07:04
  • Ummn. No. It doesn't matter what the compiler is doing *now*. Did you read the link to the SO question? You're risking a downvote. – PaulMcKenzie Jun 28 '16 at 07:05