sizeof problems, help!

E

electrixnow

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_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiters, lastPos);

while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, 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<<"HELLO 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(&tokens);++i){ // check amount of tokens
cout << tokens<<'\n';
}
}
 
L

loufoque

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

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()
 
E

electrixnow

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_control.cpp(43) : warning C4267: 'initializing' :
conversion from 'size_t' to 'int', possible loss of data
1>.\drawing_control.cpp(47) : warning C4018: '<' : signed/unsigned
mismatch
1>Linking...
1>Generating code
1>Finished generating code
1>LINK : warning LNK4199: /DELAYLOAD:OleAcc.dll ignored; no imports
found from OleAcc.dll

Thanks,

Grant
 
M

Mike Wahler

electrixnow said:
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_control.cpp(43) : warning C4267: 'initializing' :
conversion from 'size_t' to 'int', possible loss of data

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

Use vector said:
1>.\drawing_control.cpp(47) : warning C4018: '<' : signed/unsigned
mismatch

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

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

-Mike
 
E

electrixnow

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.
 
E

electrixnow

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.
 
S

Sharad Kala

| 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 "Accelarated C++" by Koenig and Moo.

Sharad
 
R

red floyd

electrixnow said:
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.

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).
 
E

electrixnow

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
 
S

Sumit Rajan

electrixnow said:
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.

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.
"Accelerated C++" is a very good choice..

You could also try out "Thinking in C++" by Bruce Eckel. It is available as
a free download:
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

Regards,
Sumit.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with Tokenizer Please 1
tokenizer class 1
MS S Compile problems MT and clr 1
Parsing tab separated file 1
Can't solve problems! please Help 0
pointer to a pointer problems 3
TF-IDF 1
Lexical Analysis on C++ 1

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top