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.

May not be the best thing to do, but here.

const char *Account::getName() const
{
     return AccName;
}
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.