Hi everyone,

I'm trying to to output an entire character of arrays in my program. I am using a header file with my class, and a source code file for my method definitions. Here are the relevant parts.

The method definition for getName()

char Account::getName() const
         {
         return *AccName;
         }

In int main()

cout << AccountX.getName()<<endl;

Where AccName is "Jamey, Jomes". I am getting an output of just "J". How can I easily output the entire array of character so it reads "Jamey, Jomes" and not just "J"? I have to keep the pointer. Thanks.

char Account::getName() const
         {
         return *AccName;
         }

is defined to return a single character, which is exactly what us happening. *AccName points to the first character in AccName.

WaltP: I realize this, but when I try to change *AccName to AccName I get an error (invalid conversion from const char* to char). Just for reference here is the definition for the original method:

char getName() const;

WaltP: I realize this, but when I try to change *AccName to AccName I get an error (invalid conversion from const char* to char).

char Account::getName() const ^ defines a single character return. You want it to return a string.

Just for reference here is the definition for the original method:

char getName() const;

If the original method won't work as defined, fix it so it will.

This article has been dead for over six months. Start a new discussion instead.