Error while defining char array

Discussion in 'C++' started by Boogie El Aceitoso, Dec 3, 2003.

  1. 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?
    Boogie El Aceitoso, Dec 3, 2003
    #1
    1. Advertising

  2. Boogie El Aceitoso

    Greg Comeau Guest

    In article <>,
    Boogie El Aceitoso <> 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?
    Greg Comeau, Dec 3, 2003
    #2
    1. Advertising

  3. Boogie El Aceitoso

    Dan W. Guest

    On Wed, 03 Dec 2003 16:56:20 +0100, 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?


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

    std::string::value_type wh[] = {'\t'};
    Dan W., Dec 3, 2003
    #3
  4. Boogie El Aceitoso

    Dario Guest

    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
    Dario, Dec 3, 2003
    #4
  5. Boogie El Aceitoso

    Mike Wahler Guest

    "Dario" <> wrote in message
    news:bql27j$fgu$...
    > 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
    Mike Wahler, Dec 3, 2003
    #5
  6. Boogie El Aceitoso

    Greg Comeau Guest

    In article <u8qzb.26531$>,
    Mike Wahler <> wrote:
    >"Dario" <> wrote in message
    >news:bql27j$fgu$...
    >> 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?
    Greg Comeau, Dec 3, 2003
    #6
  7. Boogie El Aceitoso

    Jumbo Guest

    "Mike Wahler" <> wrote in message
    news:u8qzb.26531$...
    >
    > "Dario" <> wrote in message
    > news:bql27j$fgu$...
    > > 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.
    Jumbo, Dec 3, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. johny smith
    Replies:
    8
    Views:
    400
    Peter Koch Larsen
    Jul 2, 2004
  2. lovecreatesbeauty
    Replies:
    1
    Views:
    1,007
    Ian Collins
    May 9, 2006
  3. Replies:
    3
    Views:
    719
  4. davidb
    Replies:
    0
    Views:
    752
    davidb
    Sep 1, 2006
  5. davidb
    Replies:
    6
    Views:
    1,531
    Default User
    Sep 1, 2006
Loading...

Share This Page