Simple toString() problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter van Merkerk

    #16
    Re: Simple toString() problem

    > I can't figure it out on the download page. Do I need:[color=blue]
    >
    > gcc-ada-3.3.1-20030804-1.tar.gz 12461 kb Aug 07, 2003 21:02
    > gcc-core-3.3.1-20030804-1-src.tar.gz 12958 kb Aug 07, 2003 19:11
    > gcc-core-3.3.1-20030804-1.tar.gz 2220 kb Aug 07, 2003 19:26
    > gcc-g++-3.3.1-20030804-1-src.tar.gz 2660 kb Aug 07, 2003 16:04
    > gcc-g++-3.3.1-20030804-1.tar.gz 2169 kb Aug 07, 2003 19:38
    > gcc-g77-3.3.1-20030804-1-src.tar.gz 1451 kb Aug 07, 2003 15:52
    > gcc-g77-3.3.1-20030804-1.tar.gz 1696 kb Aug 07, 2003 19:53
    > gcc-java-3.3.1-20030804-1-src.tar.gz
    >
    > or one of the many more others? My platform is WindowsME. I work
    > with Borland 5.5.1 now. I expect a file C++Win32.zip or something like
    > it but can't find it. Can someone help me out? Thank you.[/color]

    Read the download page http://www.mingw.org/download.shtml, it explains
    what you need to download and how to install.

    --
    Peter van Merkerk
    peter.van.merke rk(at)dse.nl


    Comment

    • Agent Mulder

      #17
      Re: Simple toString() problem

      "Peter van Merkerk" <merkerk@deadsp am.com> wrote in message
      news:bjhptt$j01 5t$1@ID-133164.news.uni-berlin.de...[color=blue]
      > I can't figure it out on the download page. Do I need:
      >
      > gcc-ada-3.3.1-20030804-1.tar.gz 12461 kb Aug 07, 2003 21:02
      > gcc-core-3.3.1-20030804-1-src.tar.gz 12958 kb Aug 07, 2003 19:11
      > gcc-core-3.3.1-20030804-1.tar.gz 2220 kb Aug 07, 2003 19:26
      > gcc-g++-3.3.1-20030804-1-src.tar.gz 2660 kb Aug 07, 2003 16:04
      > gcc-g++-3.3.1-20030804-1.tar.gz 2169 kb Aug 07, 2003 19:38
      > gcc-g77-3.3.1-20030804-1-src.tar.gz 1451 kb Aug 07, 2003 15:52
      > gcc-g77-3.3.1-20030804-1.tar.gz 1696 kb Aug 07, 2003 19:53
      > gcc-java-3.3.1-20030804-1-src.tar.gz
      >
      > or one of the many more others? My platform is WindowsME. I work
      > with Borland 5.5.1 now. I expect a file C++Win32.zip or something like
      > it but can't find it. Can someone help me out? Thank you.[/color]

      <Peter van Merkerk>
      Read the download page http://www.mingw.org/download.shtml, it explains
      what you need to download and how to install.
      <Peter van Merkerk>

      That's where I got that confusing list from. I think MinGW-3.0.0-1.exe
      is a candidate. Or do I get lured into some IDE then? ;-)

      "I have nothing against IDEs. I think they're great" ---Charles Petzold

      -X




      Comment

      • Peter van Merkerk

        #18
        Re: Simple toString() problem

        > <Peter van Merkerk>[color=blue]
        > Read the download page http://www.mingw.org/download.shtml, it[/color]
        explains[color=blue]
        > what you need to download and how to install.
        > <Peter van Merkerk>
        >
        > That's where I got that confusing list from.[/color]

        Besides the list there is also an explanation of the items in the list.
        [color=blue]
        > I think MinGW-3.0.0-1.exe
        > is a candidate. Or do I get lured into some IDE then? ;-)[/color]

        No need to worry, the MinGW site does not distribute IDE's.

        --
        Peter van Merkerk
        peter.van.merke rk(at)dse.nl


        Comment

        • Dirk Feytons

          #19
          Re: Simple toString() problem

          A wrote:

          [color=blue]
          > Just found out that Dev c++ 4.0 doesn't have the header file name
          > <sstream> - great![/color]

          Download and install Dev-C++ v4.9.8.0 from
          Download Dev-C++ for free. Open Source C & C++ IDE for Windows. Dev-C++ is a full-featured Integrated Development Environment (IDE) for Win32. It uses GCC, Mingw or Cygwin as compiler and libraries set.

          After that update to v4.9.8.1 using the built-in update tool.
          This version of Dev-C++ uses GCC v3.2.

          --
          Dirk

          (PGP keyID: 0x448BC5DD - http://www.gnupg.org - http://www.pgp.com)

          Comment

          • Ying Yang

            #20
            Re: Simple toString() problem


            "Dirk Feytons" <Dirk.Feytons@n orubbishplease. easynet.be> wrote in message
            news:1063028324 .659115@seven.k ulnet.kuleuven. ac.be...[color=blue]
            > A wrote:
            >
            >[color=green]
            > > Just found out that Dev c++ 4.0 doesn't have the header file name
            > > <sstream> - great![/color]
            >
            > Download and install Dev-C++ v4.9.8.0 from
            > http://sourceforge.net/projects/dev-cpp
            > After that update to v4.9.8.1 using the built-in update tool.
            > This version of Dev-C++ uses GCC v3.2.[/color]

            but v4.9.8.1 is in beta stage, and yes I have tried it and had alot of
            strange compile-time errors when developing.

            I think i will just download the missing header files from somewhere and put
            it in the system header directory.


            wewewe


            ---
            Outgoing mail is certified Virus Free.
            Checked by AVG anti-virus system (http://www.grisoft.com).
            Version: 6.0.510 / Virus Database: 307 - Release Date: 15/08/2003


            Comment

            • Ying Yang

              #21
              Re: Simple toString() problem

              I have solved my problem.

              Thanks to all that replied.



              wewewewe



              ---
              Outgoing mail is certified Virus Free.
              Checked by AVG anti-virus system (http://www.grisoft.com).
              Version: 6.0.510 / Virus Database: 307 - Release Date: 14/08/2003


              Comment

              • llewelly

                #22
                Re: Simple toString() problem

                "Agent Mulder" <mbmulder_remov e_this_@home.nl > writes:
                [color=blue]
                > "Peter van Merkerk" <merkerk@deadsp am.com> wrote in message
                > news:bjhptt$j01 5t$1@ID-133164.news.uni-berlin.de...[color=green]
                >> I can't figure it out on the download page. Do I need:
                >>
                >> gcc-ada-3.3.1-20030804-1.tar.gz 12461 kb Aug 07, 2003 21:02
                >> gcc-core-3.3.1-20030804-1-src.tar.gz 12958 kb Aug 07, 2003 19:11
                >> gcc-core-3.3.1-20030804-1.tar.gz 2220 kb Aug 07, 2003 19:26
                >> gcc-g++-3.3.1-20030804-1-src.tar.gz 2660 kb Aug 07, 2003 16:04
                >> gcc-g++-3.3.1-20030804-1.tar.gz 2169 kb Aug 07, 2003 19:38
                >> gcc-g77-3.3.1-20030804-1-src.tar.gz 1451 kb Aug 07, 2003 15:52
                >> gcc-g77-3.3.1-20030804-1.tar.gz 1696 kb Aug 07, 2003 19:53
                >> gcc-java-3.3.1-20030804-1-src.tar.gz
                >>
                >> or one of the many more others? My platform is WindowsME. I work
                >> with Borland 5.5.1 now. I expect a file C++Win32.zip or something like
                >> it but can't find it. Can someone help me out? Thank you.[/color][/color]

                This is way off-topic, so please see the mingw faq, and thier mailing
                list, at:



                I would guess you want gcc-core-3.3.1-20030804-1.tar.gz *and*
                gcc-g++-3.3.1-20030804-1.tar.gz . I think those with -src in their
                names are source code packages which you need a pre-existing
                compiler to compile. (I don't think gcc builds with borland,
                however.) g++ indicates a package for the c++ front-end. Note it
                won't work without the -core package.

                You could also try getting mingw from http://www.bloodshed.net/ ,
                which seems a little more user friendly.
                [color=blue]
                >
                > <Peter van Merkerk>
                > Read the download page http://www.mingw.org/download.shtml, it explains
                > what you need to download and how to install.
                > <Peter van Merkerk>
                >
                > That's where I got that confusing list from. I think MinGW-3.0.0-1.exe
                > is a candidate.[/color]
                [snip]

                It's not a compiler.

                Comment

                • llewelly

                  #23
                  Re: Simple toString() problem

                  "Ying Yang" <YingYang@hotma il.com> writes:
                  [color=blue]
                  > Hi,
                  >
                  > <code snippet>
                  > char* Car::toString()
                  > {
                  > //Example [XR, Holden]
                  > char* str = {"[", carID, ",", carName, "]"};
                  > return str;
                  > }[/color]

                  std::string Car::toString()
                  {
                  std::ostringstr eam out;
                  out << "[" << carID << "," << carName << "]";
                  return out.str();
                  }
                  [color=blue]
                  >
                  > Note: carID and carName are private variables of class Car
                  >
                  > Compile Error: Car.cpp initializer for scalar variable requires one element
                  >
                  > Basically, the toString() method doesn't work. Any help appreciated. Note,
                  > I'm not interested in working with the newer string data type because I want
                  > to learnto do it with pointers to char.[/color]

                  hm. Ok.

                  int Car::toString(c har* write_to, int len)
                  {
                  assert(len > 5);
                  return snprintf(write_ to, len, "[%d,%s]", carID, carName);
                  }

                  oh no, oops, C++ doesn't have snprintf. I guess you'll have to live
                  without it:

                  int Car::toString2( char* write_to, size_t len)
                  {
                  assert(len > numeric_limits< int>::digits
                  + strlen(carName) + strlen("[,]") && len < INT_MAX);
                  return sprintf(write_t o, "[%d,%s]", carID, carName);
                  }

                  I changed the interface of the toString function because it is better
                  to put the responsibility of memory allocation clearly in the
                  hands of the caller than to leave them wondering if they need to
                  free, delete, or just ignore the pointer returned.

                  You may want a better way to handle too small buffers.

                  Comment

                  • Kevin Goodsell

                    #24
                    Re: Simple toString() problem

                    A wrote:
                    [color=blue]
                    >
                    >
                    > but i need
                    >
                    > char *p = "some string" + carID + carName; // but this gives error. what to
                    > do?[/color]

                    Read the other replies. You've been given several possible answers.

                    Frankly, you don't understand the language well enough to be trusted
                    with char* strings. You should abandon the idea of using pointers and
                    use std::string instead. You'll save yourself all kinds of trouble, and
                    you'll save us time explaining why your horribly broken pointer code
                    doesn't work.

                    -Kevin
                    --
                    My email address is valid, but changes periodically.
                    To contact me please use the address from a recent posting.

                    Comment

                    • Kevin Goodsell

                      #25
                      Re: Simple toString() problem

                      Lem wrote:
                      [color=blue]
                      > I was refering to the array...=)
                      >[/color]

                      For the second time, PLEASE don't top-post! Re-read section 5 of the FAQ
                      for posting guidelines.



                      If you can't be bothered to do this, then please find a different group
                      to top-post in.

                      You said: "as str is created on the local stack, it will be
                      automatically destroyed when the function returns."

                      I said that's not relevant. And it's not. Yes, local automatic variables
                      are destroyed when the function returns. But it's still perfectly valid
                      to return one. Returning a *pointer* to a local automatic variable is
                      bad, but that isn't what you said.

                      -Kevin
                      --
                      My email address is valid, but changes periodically.
                      To contact me please use the address from a recent posting.

                      Comment

                      • Ying Yang

                        #26
                        Re: Simple toString() problem

                        >[color=blue][color=green]
                        > > Hi,
                        > >
                        > > <code snippet>
                        > > char* Car::toString()
                        > > {
                        > > //Example [XR, Holden]
                        > > char* str = {"[", carID, ",", carName, "]"};
                        > > return str;
                        > > }[/color]
                        >
                        > std::string Car::toString()
                        > {
                        > std::ostringstr eam out;
                        > out << "[" << carID << "," << carName << "]";
                        > return out.str();
                        > }
                        >[color=green]
                        > >
                        > > Note: carID and carName are private variables of class Car
                        > >
                        > > Compile Error: Car.cpp initializer for scalar variable requires one[/color][/color]
                        element[color=blue][color=green]
                        > >
                        > > Basically, the toString() method doesn't work. Any help appreciated.[/color][/color]
                        Note,[color=blue][color=green]
                        > > I'm not interested in working with the newer string data type because I[/color][/color]
                        want[color=blue][color=green]
                        > > to learnto do it with pointers to char.[/color]
                        >
                        > hm. Ok.
                        >
                        > int Car::toString(c har* write_to, int len)
                        > {
                        > assert(len > 5);
                        > return snprintf(write_ to, len, "[%d,%s]", carID, carName);
                        > }
                        >
                        > oh no, oops, C++ doesn't have snprintf. I guess you'll have to live
                        > without it:
                        >
                        > int Car::toString2( char* write_to, size_t len)
                        > {
                        > assert(len > numeric_limits< int>::digits
                        > + strlen(carName) + strlen("[,]") && len < INT_MAX);
                        > return sprintf(write_t o, "[%d,%s]", carID, carName);
                        > }
                        >
                        > I changed the interface of the toString function because it is better
                        > to put the responsibility of memory allocation clearly in the
                        > hands of the caller than to leave them wondering if they need to
                        > free, delete, or just ignore the pointer returned.
                        >
                        > You may want a better way to handle too small buffers.[/color]

                        Thanks dude, but i solved my problem by simply using the methods from
                        <string.h>: strcpy and strcat. It was much more simpler, but I guess the
                        downfall is the use of a global buffer of a very large size. Anyway, memory
                        is dirt cheap these days, so no harm done.


                        wewewe


                        ---
                        Outgoing mail is certified Virus Free.
                        Checked by AVG anti-virus system (http://www.grisoft.com).
                        Version: 6.0.510 / Virus Database: 307 - Release Date: 14/08/2003


                        Comment

                        • Karl Heinz Buchegger

                          #27
                          Re: Simple toString() problem



                          Ying Yang wrote:[color=blue]
                          >
                          > Thanks dude, but i solved my problem by simply using the methods from
                          > <string.h>: strcpy and strcat. It was much more simpler, but I guess the
                          > downfall is the use of a global buffer of a very large size. Anyway, memory
                          > is dirt cheap these days, so no harm done.[/color]

                          That sounds as if there is a problem sitting and waiting in your code.
                          It waits until it can do the most harm, then it will show up :-)

                          --
                          Karl Heinz Buchegger
                          kbuchegg@gascad .at

                          Comment

                          Working...