Click here for important information about

OOB C++ . . can't display the string properly

November 27, 2011 at 12:49:50
Specs: Windows 7
#include <iostream>
#include <string>

using namespace std;

class Book
char title[30];
int year;
char publisher[30];
void set_Title(char []);
void set_Year(int);
void set_Publisher(char []);
char get_Title();
int get_Year();
char get_Publisher();

void Book::set_Title(char B[])
strcpy(title, B);
void Book::set_Year(int yr)
void Book::set_Publisher(char dir[])
strcpy(publisher, dir);
char Book::get_Title()
return title [0];
int Book::get_Year()
return year;
char Book::get_Publisher()
return publisher[0];

int main()
Book A;
cout<<"The name of the title is: " << A.get_Title() << endl;
cout<<"The year is it published: " << A.get_Year() << endl;
cout<<"THe publisher's name: " << A.get_Publisher() << endl;

I want to display the string output to "YoureMyEverything" and not "Y"

help please

See More: OOB C++ . . cant display the string properly

November 29, 2011 at 07:44:36
char Book::get_Title()
You're returning a char, not a char*. Either return a char*, or use the string class. You're importing it anyways, so you might as well take advantage.

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question