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[i]<<'\n';
}
} 9 1873
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()
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
"electrixnow" <info...@charter.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... 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<>::size_type
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
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.
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.
"electrixnow" <info...@charter.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 "Accelarated C++" by Koenig and Moo.
Sharad
electrixnow wrote: 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).
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
"electrixnow" <info...@charter.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... 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/...ngInCPP2e.html
Regards,
Sumit.
--
Sumit Rajan <su****@msdc.hcltech.com> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cody |
last post by:
no this is no trollposting and please don't get it wrong but iam very
curious why people still use C instead of other languages especially C++.
i heard people say C++ is slower than C but i can't...
|
by: ajikoe |
last post by:
Hello I have this code:
void sizeArr(float a){
cout << sizeof(a) << endl;
}
void test(void){
float val = {1, 2, 0.1};
sizeArr(val); // return 4
|
by: Abhishek Srivastava |
last post by:
Hi,
Somebody recently asked me to implement the sizeof operator, i.e. to
write a function that accepts a parameter of any type, and without
using the sizeof operator, should be able to return...
|
by: GRenard |
last post by:
Hello,
We just switch in our company to VisualStudio 2005 and the new ATL
library.
We use a wrapper to use CFileDialog. Its name is CFileDialogDeluxe
Here the call
CFileDialogDeluxe...
|
by: Spiros Bousbouras |
last post by:
Do you have an example of an implementation where
sizeof(short int) does not divide sizeof(int) or
sizeof(int) does not divide sizeof(long int) or
sizeof(long int) does not divide sizeof(long long...
|
by: venkat |
last post by:
Hi,
I have written a program
void main()
{
printf("%d %d\n", sizeof main, sizeof(main()));
}
in this program the output is 1 and 4,
|
by: Richard Tobin |
last post by:
Please excuse me if this has already been covered.
Given
char x;
is
sizeof(x)
|
by: =?Utf-8?B?RnJhbg==?= |
last post by:
sHi!
I have a very strange problem with the behaviour of the sizeof command. I
have tested it in vc6,vc 2001 and vc 2003. The problem is quite simple.
When I made a sizeof to the next struct,...
|
by: CodeMonk3y |
last post by:
gotta question on sizeof keyword
does the sizeof keyword calcuates the size at compile time or run time ??
-- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |