sizeof problems, help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • electrixnow

    #1

    sizeof problems, help!

    Can anyone tell me who sizeof &tokens only return a int of 4 no matter
    how many
    strings that are in the token[].

    thanks,

    Grant


    #include <cstring>
    #include <iostream>
    #include <string>
    #include <vector>

    using namespace std;


    void Tokenize(const string& str,
    vector<string>& tokens,
    const string& delimiters = " ,\t\n")

    {

    // Skip delimiters at beginning.
    string::size_ty pe lastPos = str.find_first_ not_of(delimite rs, 0);
    // Find first "non-delimiter".
    string::size_ty pe pos = str.find_first_ of(delimiters, lastPos);

    while (string::npos != pos || string::npos != lastPos)
    {
    // Found a token, add it to the vector.
    tokens.push_bac k(str.substr(la stPos, pos - lastPos));
    // Skip delimiters. Note the "not_of"
    lastPos = str.find_first_ not_of(delimite rs, pos);
    // Find next "non-delimiter"
    pos = str.find_first_ of(delimiters, lastPos);
    }
    }

    int main()
    {
    vector<string> tokens;
    string str(";1,2,3,4,5 ,6,7,8,9,0"); // replace with getline
    string start = str.substr(0,1) ;
    if(start == ";")cout<<"HELL O WORLD"<<'\n'; // skip this line for
    comments
    int len = str.length();
    for (int a=0; a<len; ++a)
    str[a]=toupper(str[a]);
    Tokenize(str, tokens);
    for (int i=0;i<sizeof(&t okens);++i){ // check amount of tokens
    cout << tokens[i]<<'\n';
    }
    }

  • loufoque

    #2
    Re: sizeof problems, help!

    electrixnow a écrit :[color=blue]
    > Can anyone tell me who sizeof &tokens only return a int of 4 no matter
    > how many
    > strings that are in the token[].[/color]

    It will always return 4 on a x86 architecture, yes, as &tokens is a
    pointer to a vector<string>.
    The number of elements is available with tokens.size()

    Comment

    • electrixnow

      #3
      Re: sizeof problems, help!

      Thanks alot. I still don' understand why. I am using VC++ to compile,
      why do you think I get the following warnings. Should I be concerned?

      1>.\drawing_con trol.cpp(43) : warning C4267: 'initializing' :
      conversion from 'size_t' to 'int', possible loss of data
      1>.\drawing_con trol.cpp(47) : warning C4018: '<' : signed/unsigned
      mismatch
      1>Linking...
      1>Generating code
      1>Finished generating code
      1>LINK : warning LNK4199: /DELAYLOAD:OleAc c.dll ignored; no imports
      found from OleAcc.dll

      Thanks,

      Grant

      Comment

      • Mike Wahler

        #4
        Re: sizeof problems, help!


        "electrixno w" <info...@charte r.net> wrote in message
        news:1140055584 .177303.294000@ o13g2000cwo.goo glegroups.com.. .[color=blue]
        > Thanks alot. I still don' understand why. I am using VC++ to compile,
        > why do you think I get the following warnings. Should I be concerned?
        >
        > 1>.\drawing_con trol.cpp(43) : warning C4267: 'initializing' :
        > conversion from 'size_t' to 'int', possible loss of data[/color]

        Type 'int' is not guaranteed to be able to represent
        the largest possible number of vector elements.

        Use vector<>::size_ type
        [color=blue]
        > 1>.\drawing_con trol.cpp(47) : warning C4018: '<' : signed/unsigned
        > mismatch[/color]

        The container types 'size_type' are unsigned. Type
        'int' is signed.

        Which C++ book(s) are you reading?

        -Mike


        Comment

        • electrixnow

          #5
          Re: sizeof problems, help!

          I just started C++ without fear, Ivor Horton's VC++ 5, and Special
          Edition using VC++ 5 by QUE books. I really don't like any for C++. I
          need a good solid C++ ref book with examples.
          Do you know of one or any online ref's? I have found that online refs
          may be mis leading because I might not be using the proper compiler or
          libraries.

          Comment

          • electrixnow

            #6
            Re: sizeof problems, help!

            Just to let you know, I have only started back in programming. I
            stopped in 1991 when I switched jobs. Many things have changed. I
            understand OOD and project planning, but the codeing syntax and usaged
            has change.

            Comment

            • Sharad Kala

              #7
              Re: sizeof problems, help!


              "electrixno w" <info...@charte r.net> wrote in message

              | Just to let you know, I have only started back in programming. I
              | stopped in 1991 when I switched jobs. Many things have changed. I
              | understand OOD and project planning, but the codeing syntax and usaged
              | has change.

              Get "Accelarate d C++" by Koenig and Moo.

              Sharad


              Comment

              • red floyd

                #8
                Re: sizeof problems, help!

                electrixnow wrote:[color=blue]
                > I just started C++ without fear, Ivor Horton's VC++ 5, and Special
                > Edition using VC++ 5 by QUE books. I really don't like any for C++. I
                > need a good solid C++ ref book with examples.
                > Do you know of one or any online ref's? I have found that online refs
                > may be mis leading because I might not be using the proper compiler or
                > libraries.
                >[/color]

                If you're using VC5 (VC97), then you are using a *horrendously* out of
                date compiler. The C++ standard dates from 1998, and Microsoft didn't
                really get compliance right until VC7.1 (2003).

                Comment

                • electrixnow

                  #9
                  Re: sizeof problems, help!

                  I am using Microsoft Visual C++ 2005 Express Edition. It's the latest
                  release. You misunderstood that I was reading a book on Visual C++
                  release 5.

                  I have ordered Microsoft's Visual Studio.

                  Grant

                  Comment

                  • Sumit Rajan

                    #10
                    Re: sizeof problems, help!


                    "electrixno w" <info...@charte r.net> wrote in message
                    news:1140093319 .962538.261480@ o13g2000cwo.goo glegroups.com.. .[color=blue]
                    >I am using Microsoft Visual C++ 2005 Express Edition. It's the latest
                    > release. You misunderstood that I was reading a book on Visual C++
                    > release 5.[/color]

                    However, I think Sharad's suggestion is perfect. C++ has changed over time
                    and I think you need something more in touch with C++ as it is today.
                    "Accelerate d C++" is a very good choice..

                    You could also try out "Thinking in C++" by Bruce Eckel. It is available as
                    a free download:


                    Regards,
                    Sumit.
                    --
                    Sumit Rajan <sumitr@msdc.hc ltech.com>




                    Comment

                    Working...