By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

Error while defining char array

P: n/a
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?
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
In article <rq********************************@4ax.com>,
Boogie El Aceitoso <fr****@telefonica.net> wrote:
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?
--
Greg Comeau/4.3.3:Full C++03 core language + more Windows backends
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Jul 22 '05 #2

P: n/a
On Wed, 03 Dec 2003 16:56:20 +0100, Boogie El Aceitoso
<fr****@telefonica.net> wrote:
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'};
Jul 22 '05 #3

P: n/a
Boogie El Aceitoso wrote:
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

Jul 22 '05 #4

P: n/a

"Dario" <da***@despammed.com> wrote in message
news:bq**********@fata.cs.interbusiness.it...
Boogie El Aceitoso wrote:
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
Jul 22 '05 #5

P: n/a
In article <u8******************@newsread2.news.pas.earthlink .net>,
Mike Wahler <mk******@mkwahler.net> wrote:
"Dario" <da***@despammed.com> wrote in message
news:bq**********@fata.cs.interbusiness.it...
Boogie El Aceitoso wrote:
> 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.
--
Greg Comeau/4.3.3:Full C++03 core language + more Windows backends
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Jul 22 '05 #6

P: n/a

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:u8******************@newsread2.news.pas.earth link.net...

"Dario" <da***@despammed.com> wrote in message
news:bq**********@fata.cs.interbusiness.it...
Boogie El Aceitoso wrote:
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.
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.