How to use same variables in different classes

Hello,

I'm fairly new to programming in general, and i've had people say C++ isn't a starter language, but im up for the challenge.

i've spent about all day trying to figure this out, trying out different code, and googling and searching for an answer, but as the day ends, im starting to give up, and going to post my problem.

When i use the same variable that is being declared in "fugie" class, and taking that and showing a message in the main class. it works perfectly, but what my problem is, that i can't get so that a user can edit the variable, then using that variable to post the message he wrote in the main class. Here's an example, the USER must edit the variable, then return what he edited. Like, i say, "What is your name? ", then they must type their name, and their name goes to a variable, and then later on, return their name, but that variable or code being stored in a different class. The code below is when I SPECIFY what the variable must be, but i cant get to what the USER wants to specify.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

class fugie{
    public:
        string name;
};

int main()
{
    fugie object;
    object.name = "test";

    cout << object.name;

    return 0;
}



This may be hard to understand, as it is late and im tired from thinking so hard, If you need, i can try explaining it better tomorrow.

Thank you for understanding
Why can't you do this?
1
2
3
4
5
6
// ...
cout << "What is your name? ";
cin >> object.name;

cout << "Nice to meet you " << object.name;
// ... 
Volatile Pulse always beats me to it :D

Well, yes. i know about that way, but not what im looking for, im looking a way to import variables from different classes,

class 1;

string name;


Then import to class 2;

class 2;

string name; <--- that variable being from class 1,
¿A transplant?
Topic archived. No new replies allowed.