• Advertisement

Archived

This topic is now archived and is closed to further replies.

length of a string

This topic is 5252 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
If it''s the string class then I assume there is a length function. If it''s an array just loop through it and count until you find the null terminator.

Share this post


Link to post
Share on other sites
In a C++ string class it's the size() function.

EDIT: Argh, missed the "in a file" part. Sorry.

[edited by - DaTroof on October 5, 2003 12:06:39 AM]

Share this post


Link to post
Share on other sites
i don''t understand the question,you want the size of a string in a file, but before reading it?

Share this post


Link to post
Share on other sites
quote:
Original post by hello_there
but there might be other stuff on the line that i don't want to load.


Have you even read the documentation for that function ?
You obviously don't understand what it does.
Particularly what a 'line' is in this context.

If your string is null-terminated, getline, with a terminator of '\0' will read it. If not, you have to figure out where you want the string to end by yourself : space, tab, newline, comma, whatever.

The computer cannot "guess" when to stop reading if you don't tell it the length (surprise, surprise), or a character that marks the end.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on October 6, 2003 1:35:09 AM]

Share this post


Link to post
Share on other sites
oh wait never mind i though of a way to do it. also i now how it works i was meaning if the string started in the middle of the line. is a char always 1 byte on any computer?

Share this post


Link to post
Share on other sites
quote:
Original post by hello_there
Is a char always 1 byte on any computer?


Yes.

By the way, C++ defines 'byte' as the size of one char, not the other way round.

It says nothing about the number of bits, though.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on October 6, 2003 3:16:09 AM]

Share this post


Link to post
Share on other sites

  • Advertisement