Error while defining char array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boogie El Aceitoso

    Error while defining char array

    Hi,

    I have this code:

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

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

    What am I doing wrong?
  • Greg Comeau

    #2
    Re: Error while defining char array

    In article <rq1ssvgf60om36 94m7tg2f06cfprr ab38f@4ax.com>,
    Boogie El Aceitoso <frr149@telefon ica.net> wrote:[color=blue]
    >I have this code:
    >
    >std::string::v alue_type * wh[] = {'\t'};
    >
    >But it gives a compiler error, comlaining that it can't convert int to char.
    >
    >What am I doing wrong?[/color]

    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?

    Comment

    • Dan W.

      #3
      Re: Error while defining char array

      On Wed, 03 Dec 2003 16:56:20 +0100, Boogie El Aceitoso
      <frr149@telefon ica.net> wrote:
      [color=blue]
      >Hi,
      >
      >I have this code:
      >
      >std::string::v alue_type * wh[] = {'\t'};
      >
      >But it gives a compiler error, comlaining that it can't convert int to char.
      >
      >What am I doing wrong?[/color]

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

      std::string::va lue_type wh[] = {'\t'};

      Comment

      • Dario

        #4
        Re: Error while defining char array

        Boogie El Aceitoso wrote:
        [color=blue]
        > Hi,
        >
        > I have this code:
        >
        > std::string::va lue_type * wh[] = {'\t'};
        >
        > But it gives a compiler error, comlaining that it can't convert int to char.
        >
        > What am I doing wrong?[/color]

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

        - Dario

        Comment

        • Mike Wahler

          #5
          Re: Error while defining char array


          "Dario" <dario@despamme d.com> wrote in message
          news:bql27j$fgu $1@fata.cs.inte rbusiness.it...[color=blue]
          > Boogie El Aceitoso wrote:
          >[color=green]
          > > Hi,
          > >
          > > I have this code:
          > >
          > > std::string::va lue_type * wh[] = {'\t'};
          > >
          > > But it gives a compiler error, comlaining that it can't convert int to[/color][/color]
          char.[color=blue][color=green]
          > >
          > > What am I doing wrong?[/color]
          >
          > Rewrite as:
          > std::string::va lue_type * wh[] = {"\t"};
          > or as:
          > std::string::va lue_type wh[] = {'\t'};[/color]

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

          char wh = '\t';

          -Mike


          Comment

          • Greg Comeau

            #6
            Re: Error while defining char array

            In article <u8qzb.26531$sb 4.4831@newsread 2.news.pas.eart hlink.net>,
            Mike Wahler <mkwahler@mkwah ler.net> wrote:[color=blue]
            >"Dario" <dario@despamme d.com> wrote in message
            >news:bql27j$fg u$1@fata.cs.int erbusiness.it.. .[color=green]
            >> Boogie El Aceitoso wrote:[color=darkred]
            >> > std::string::va lue_type * wh[] = {'\t'};
            >> >
            >> > But it gives a compiler error, comlaining that it can't convert int to
            >> > char.
            >> >
            >> > What am I doing wrong?[/color]
            >>
            >> Rewrite as:
            >> std::string::va lue_type * wh[] = {"\t"};
            >> or as:
            >> std::string::va lue_type wh[] = {'\t'};[/color]
            >
            >Right, but I don't understand why OP is using string::value_t ype
            >anyway, since by definition it's 'char'.
            >
            >char wh = '\t';[/color]

            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?

            Comment

            • Jumbo

              #7
              Re: Error while defining char array


              "Mike Wahler" <mkwahler@mkwah ler.net> wrote in message
              news:u8qzb.2653 1$sb4.4831@news read2.news.pas. earthlink.net.. .[color=blue]
              >
              > "Dario" <dario@despamme d.com> wrote in message
              > news:bql27j$fgu $1@fata.cs.inte rbusiness.it...[color=green]
              > > Boogie El Aceitoso wrote:
              > >[color=darkred]
              > > > Hi,
              > > >
              > > > I have this code:
              > > >
              > > > std::string::va lue_type * wh[] = {'\t'};
              > > >
              > > > But it gives a compiler error, comlaining that it can't convert int to[/color][/color]
              > char.[color=green][color=darkred]
              > > >
              > > > What am I doing wrong?[/color]
              > >
              > > Rewrite as:
              > > std::string::va lue_type * wh[] = {"\t"};
              > > or as:
              > > std::string::va lue_type wh[] = {'\t'};[/color]
              >
              > Right, but I don't understand why OP is using string::value_t ype
              > anyway, since by definition it's 'char'.
              >[/color]
              Probably just trying to get his head around it.


              Comment

              Working...