I'm writing a piece of code to pass an array into a variable within an object, and then to be able to access the array again. I'm very new at programming so don't be too hard on me .
What I don't understand is how to input an array in console, store it in a variable within an object (which is in a seperate file), and then be able to access the array from the object and print it out.
Here's the Main function, Computer.cpp. It isn't in the least bit finished and I'm simply working on this issue before I do the rest of the code.
Code:
#include <iostream>
#include "Computer.h"
int main()
{
using namespace std;
char mdl[15];
char* mdl1;
cout << "What model of computer do you use?: ";
cin >> mdl;
Computer mBook;
mBook.SetModel(mdl);
mBook.GetModel(mdl1);
cout << mdl1 << endl;
return 0;
}
And here's my object:
Code:
class Computer {
public:
void SetModel(char arg[15]){
iModel = arg;
}
void GetModel(char *arg1){
arg1 = iModel;
}
private:
char iModel[15];
};
I was attempting to use pointers to get the address of iModel, but I couldn't figure it out.