I'm fairly new to programming, wondering how I could do something like this...
class Cdata
{
public:
char something;
void functiion()
{
char something= "text";
}
};
I get an error
"cannot convert from 'char [length]' to 'char"
Printable View
I'm fairly new to programming, wondering how I could do something like this...
class Cdata
{
public:
char something;
void functiion()
{
char something= "text";
}
};
I get an error
"cannot convert from 'char [length]' to 'char"
You have declared a member of your class to be a char, yet you are trying to assign an array of chars. The declaration of the type char need's to be an array. Then you could use strcpy(something,"hello"); to assign the variable.
Ah, thank you very much! I totally forgot about strcpy.
I don't think the effects of this code will be what you're expecting. in function() you make a local variable, something, which you attempt to assign "text" to (as subdene said, use strcpy). The char something; variable which belongs to Cdata will not get this value, as it's not in scope. If you want to assign "text" to something then drop the char infront of it. For example:Code:class Cdata
{
public:
char something;
void functiion()
{
char something= "text";
}
};
Also, you didn't allocate enough memory to store "text" in somethingCode:class Cdata
{
public:
char something[4];
void functiion()
{
strcpy(something, "text");
}
};