I used a **char
pointer/array to store a list of char values.
I have a method to store the values, but my method to retrieve these values have not been as successful.
This is my method that sets the values...
char **names;
char *input_name;
int studentNameSize;
void Students::setStudentNames()
{
names = new char*[studentNameSize];
for(int i=0; i<studentNameSize; i++)
{
names[i] = new char[60];
cout << "Input name" << i << ": \n";
cin >> input_name;
strcpy(names[i],input_name);
cout << names[i] << "\n";
}
}
This is my method and it only return the memory size and not the actual values. It returns 0x(size of the array
, i.e. 0x03
instead of something like Bob; Charles; Mike
const char** Students::getStudentNames()
{
for(int i=0; i<this->studentNameSize; i++)
{
return this->names[i];
}
}
Sorry, I'm new to C++ and I need some assistance with the friend ostream& operator<<
. Basically I know how to output to file now but I don't get how to use the friend ostream& operator<<
method of doing it. I have something like this but I am really lost as to how I can output to file this way.
ostream& operator<< (ostream& ostream, const Students& students)
{
os << students.getStudentNames();
return os;
}