string::size_type

Started by
18 comments, last by swiftcoder 11 years, 6 months ago

SIZE_T just returns a integar or length of bytes for the string. SIZE_T is the same function of sizeof(). SIZE_T just stores the integar length of a string or what not.



SIZE_T StringLength;
string Greeting = "Hello, I'm George!";
StringLength = sizeof(Greeting);
cout << StringLength;



As you see the SIZE_T is a typdef that stores the integer of length. Where as sizeof function returns the length of the string Greeting.


std::string varString = "Hello World";
unsigned int size = sizeof(varString);
sizeof DOES NOT RETURN THE SIZE OF THE STRING INSIDE THE STD::STRING

It returns the size of the string class. The string class uses dynamic memory to store cstrings. So only the pointer is counted as well as any other members. If you want the size of an std::string you use .size();

If this post or signature was helpful and/or constructive please give rep.

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

// Easy to learn 2D Game Library c++

SFML2.2 Download http://www.sfml-dev.org/download.php

SFML2.2 Tutorials http://www.sfml-dev.org/tutorials/2.2/

// Excellent 2d physics library Box2D

http://box2d.org/about/

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

Advertisement

SIZE_T just returns a integar or length of bytes for the string. SIZE_T is the same function of sizeof(). SIZE_T just stores the integar length of a string or what not.



SIZE_T StringLength;
string Greeting = "Hello, I'm George!";
StringLength = sizeof(Greeting);
cout << StringLength;



As you see the SIZE_T is a typdef that stores the integer of length. Where as sizeof function returns the length of the string Greeting.


First of all

http://www.cplusplus.com/reference/clibrary/cstring/size_t/

http://msdn.microsoft.com/en-us/library/4s7x1k91%28v=vs.71%29.aspx

there is size_t; and plus sizeof() returns bytes of characters. Rather it be a sturct, a class or whatever.

I helped out and that's it.
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

[quote name='SIC Games' timestamp='1349931097' post='4988961']
SIZE_T just returns a integar or length of bytes for the string. SIZE_T is the same function of sizeof(). SIZE_T just stores the integar length of a string or what not.



SIZE_T StringLength;
string Greeting = "Hello, I'm George!";
StringLength = sizeof(Greeting);
cout << StringLength;



As you see the SIZE_T is a typdef that stores the integer of length. Where as sizeof function returns the length of the string Greeting.


std::string varString = "Hello World";
unsigned int size = sizeof(varString);
sizeof DOES NOT RETURN THE SIZE OF THE STRING INSIDE THE STD::STRING

It returns the size of the string class. The string class uses dynamic memory to store cstrings. So only the pointer is counted as well as any other members. If you want the size of an std::string you use .size();
[/quote]

sizeof returns the length in bytes of a char. - whether it be a array or what not. Whatever - I was trying to help out; screw that idea.
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

there is size_t; and plus sizeof() returns bytes of characters. Rather it be a sturct, a class or whatever.

“string” is a structure, so sizeof() returns the size of that structure, not the size of the string it manages.
If it was instead:
const char szString[] = "Hello fellow citizens.";
Then sizeof() would return the number of characters, including the terminating NULL.



screw that idea.

I supported you on SIZE_T but I feel less sorry for you after you posted this.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


sizeof returns the length in bytes of a char. - whether it be a array or what not. Whatever - I was trying to help out; screw that idea.

You are, unfortunately, blatantly wrong on this count.

sizeof() returns the correct size for the given type, or the correct length of a statically allocated array. std::string uses dynamically allocated memory to store the string contents, so sizeof() will not see that memory.

#include <string>
#include <cassert>
int main() {
std::string A = "Hello, World!";
std::string B = "Hi";

assert( sizeof(A) == sizeof(B) );
}

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


[quote name='SIC Games' timestamp='1349964519' post='4989104']
there is size_t; and plus sizeof() returns bytes of characters. Rather it be a sturct, a class or whatever.

“string” is a structure, so sizeof() returns the size of that structure, not the size of the string it manages.
If it was instead:
const char szString[] = "Hello fellow citizens.";
Then sizeof() would return the number of characters, including the terminating NULL.



screw that idea.

I supported you on SIZE_T but I feel less sorry for you after you posted this.


L. Spiro
[/quote]

Watever, dude. Seriously, all I hear is "IM WRONG" "I AM WRONG" from all you people on here. So, whatever. Have a good day; dude.
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

[quote name='SIC Games' timestamp='1349964757' post='4989106']
sizeof returns the length in bytes of a char. - whether it be a array or what not. Whatever - I was trying to help out; screw that idea.

You are, unfortunately, blatantly wrong on this count.

sizeof() returns the correct size for the given type, or the correct length of a statically allocated array. std::string uses dynamically allocated memory to store the string contents, so sizeof() will not see that memory.

#include <string>
#include <cassert>
int main() {
std::string A = "Hello, World!";
std::string B = "Hi";

assert( sizeof(A) == sizeof(B) );
}

[/quote]

Yeah you too have a good day, keep on warning people; bro! Cause you're cool like that.
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX
I have been wrong too; it is all about how you handle it.
http://www.gamedev.net/topic/628778-compressing-vertex-attribute-normals/page__p__4965067#entry4965067

People don’t lose respect for you for being wrong. They lose respect for you for handling it poorly.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


I have been wrong too; it is all about how you handle it.
http://www.gamedev.n...67#entry4965067

People don’t lose respect for you for being wrong. They lose respect for you for handling it poorly.


L. Spiro


True. I probably woke up on the wrong side of the bed today. You're right bro, if a game critic gave me poor game review - probably would aggravate me. So, yeah - I agree I have to react more proactive and professional about. I also have to realize critizism comes in a helping manner and less of a attack. I was being defensive and that's not good demonstration for others to see on this forum. Professionalism is the way to lead people in the right direction. Which, again I have to work upon if I am ever going to be taken seriously. So, yeah I agree with the quote above.
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX
And with that, we are far enough off topic.

@markrodgers11 - feel free to create a new thread if you still have questions.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement