length of a string
i have a string in a file and i want to know how long it is how would i find it''s length. in c++;
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.
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]
EDIT: Argh, missed the "in a file" part. Sorry.
[edited by - DaTroof on October 5, 2003 12:06:39 AM]
Yeah, getline with a ''\0'' terminator ought to work.
[ 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 ]
[ 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 ]
i don''t understand the question,you want the size of a string in a file, but before reading it?
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement