Quick c++ Question

Associate
Joined
2 Oct 2003
Posts
2,121
Location
Chester
Code:
#include <iostream>
using namespace std;

struct movies_t {
	char title;
	int year;
};

struct friends_t {
	char name;
	int age;
	movies_t favFilm;
} robert, aled;

int main()
{
	aled.favFilm.title = "The Matrix";
	cout << aled.favFilm.title;
	return 0;
}

e:\Visual Studio Projects\pointers\pointers.cpp(17): error C2440: '=' : cannot convert from 'const char [11]' to 'char'


How do I fix this? :(
 
in the movies_t structure you have declare title as a single 'char' varible meaning correctly it should be used like:

aled.favFilm.title = 't';

To fix this so you can use a string, you need a char array (or you could use a string varible),

e.g.

char title[30];

you then i think need to use strcpy() to fill the array i.e strcpy(aled.favFilm.title, "The Matrix");

You need to include string.h if you take this route.
 
Back
Top Bottom