char cannot convert to *char

I have a
char a[20][20];
char name[30];
when i write: if (a[i][2]=='name') c++ give me the error char can not convert to *char.
My programm read a matrix of char and when it finds variable: name must open a file. Can anyone help me?
Something like that f.open(name);
Single quotes are for character literals. You need to use double quotes: if (a[i][2] == "name")

EDIT: that was completely wrong, as kempofighter pointed out.
Last edited on
can you post the actual code?
Actually, since a[i][2] is a character, that won't work either.
Last edited on
First, single quotes can only be used to identify one character. Second you need at least one std::string object to use the operator== which is overloaded in a variety of ways for std::string objects. Third, name is the name of an array so putting it between single or double quotes makes no sense. Lastly a[i][2] will always return a reference to a single character. To be honest I don't understand your requirements well at all.

You need strcmp function from the <cstring> library if you want to compare character arrays. If you want to use std::string with getline then you can use the operator== for comparing std::string objects.

A c++ alternative to your 2d array would be
std::vector<std::string> theStrings;

Search for getline for info on how to read data from a file stream into a std::string.
Topic archived. No new replies allowed.