Error while defining char array

  • Thread starter Boogie El Aceitoso
  • Start date
B

Boogie El Aceitoso

Hi,

I have this code:

std::string::value_type * wh[] = {'\t'};

But it gives a compiler error, comlaining that it can't convert int to char.

What am I doing wrong?
 
G

Greg Comeau

I have this code:

std::string::value_type * wh[] = {'\t'};

But it gives a compiler error, comlaining that it can't convert int to char.

What am I doing wrong?

Bad diagnostic since the error is not in converting an int to a char
but in converting a char into a valuetype *. Should it just be a
valuetype?
 
D

Dan W.

Hi,

I have this code:

std::string::value_type * wh[] = {'\t'};

But it gives a compiler error, comlaining that it can't convert int to char.

What am I doing wrong?

Declaring an array of pointers-to-value-type. Try:

std::string::value_type wh[] = {'\t'};
 
D

Dario

Boogie said:
Hi,

I have this code:

std::string::value_type * wh[] = {'\t'};

But it gives a compiler error, comlaining that it can't convert int to char.

What am I doing wrong?

Rewrite as:
std::string::value_type * wh[] = {"\t"};
or as:
std::string::value_type wh[] = {'\t'};

- Dario
 
M

Mike Wahler

Dario said:
Boogie said:
Hi,

I have this code:

std::string::value_type * wh[] = {'\t'};

But it gives a compiler error, comlaining that it can't convert int to char.

What am I doing wrong?

Rewrite as:
std::string::value_type * wh[] = {"\t"};
or as:
std::string::value_type wh[] = {'\t'};

Right, but I don't understand why OP is using string::value_type
anyway, since by definition it's 'char'.

char wh = '\t';

-Mike
 
G

Greg Comeau

Dario said:
Boogie said:
std::string::value_type * wh[] = {'\t'};

But it gives a compiler error, comlaining that it can't convert int to
char.

What am I doing wrong?

Rewrite as:
std::string::value_type * wh[] = {"\t"};
or as:
std::string::value_type wh[] = {'\t'};

Right, but I don't understand why OP is using string::value_type
anyway, since by definition it's 'char'.

char wh = '\t';

Probably the OP also has wchar_t's and maybe some other,
and wants to make that connection clear.
 
J

Jumbo

Mike Wahler said:
Dario said:
Boogie said:
Hi,

I have this code:

std::string::value_type * wh[] = {'\t'};

But it gives a compiler error, comlaining that it can't convert int to char.

What am I doing wrong?

Rewrite as:
std::string::value_type * wh[] = {"\t"};
or as:
std::string::value_type wh[] = {'\t'};

Right, but I don't understand why OP is using string::value_type
anyway, since by definition it's 'char'.
Probably just trying to get his head around it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top