Skip to main content
gamedev.net
🔒 Locked

STL String

Started by WizHarDx 8 replies 250+ views
Original Post
WizHarDx
WizHarDx
Im creating a console for my game and im using STL''s string. The odd thing bout the string is sometimes just crashes randomly. I think the errors occure when use: Insert() function copy one string to another do any of you know how to get round this error? thanx in advance Iain
who is it that keeps on nicking WizHarD name !! :P
Fruny
Fruny
Which insert() function ? How did you make the copy ?
Do you have a minimal test case that crashes ?

<pedantic> The std::string class is part of the C++ standard library, but not of the STL </pedantic>


[ 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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
SabreMan
SabreMan
quote:
Original post by Fruny
The std::string class is part of the C++ standard library, but not of the STL

std::string is part of both. Having said that, I'd prefer it if people stopped referring to it as "STL string" (which also happens with vector and friends), since there's often an implication string is somehow an optional add-on to C++ and not actually a part of the Standard Library.

[edited by - SabreMan on January 5, 2003 9:22:38 AM]
WizHarDx
WizHarDx
ok im using the C++ standard libary string

to copy the string''s I just use the = operator

String1 = String2;

I use insert to insert 1 character, ie:
insert(m_Cursor,1,result);

they seem to cause it to crash. I don''t use empty anymore but that also caused it to crash.

Note that insert & operator= don''t crash every time, sort of when I reach a certain position.
who is it that keeps on nicking WizHarD name !! :P
civguy
civguy
maybe m_cursor is illegal argument at times
Fruny
Fruny
The overloaded string& std::insert( size_type idx, size_type num, char c) fails if idx > size(). If you somehow corrupt the string, it may crash on any operation.


[ 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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Dean Harding
Dean Harding
quote:
Original post by SabreMan
std::string is part of both. Having said that, I''d prefer it if people stopped referring to it as "STL string" (which also happens with vector and friends), since there''s often an implication string is somehow an optional add-on to C++ and not actually a part of the Standard Library.



Hang on, doesn''t STL stand for "Standard Template Library"? I always thought "STL" and "C++ Standard Library" were interchangeable?

If I had my way, I''d have all of you shot!


codeka.com - Just click it.

SiCrane
SiCrane
quote:
Original post by Dean Harding

Hang on, doesn''t STL stand for "Standard Template Library"? I always thought "STL" and "C++ Standard Library" were interchangeable?




Not interchangable. The Standard Template Library was incorporated as part of the C++ standard library, but there are parts of the standard library that are not parts of the STL, like locales.
Fruny
Fruny
Not every class template is part of the STL, even though the string classes do qualify as a STL-compatible container (of char, wchar_t, unsigned char... whatever ).

The C++ standard library includes

- the C standard library (yup)
- the Standard Template Library (STL)
- strings
- iostreams (NOT the old iostream.h)
- complex numbers
- valarrays
- auto_ptr
- locales

The STL consists in
- containers
- iterators
- algorithms
- functors
- allocators

And probably more stuff I have forgotten



[ 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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Dean Harding
Dean Harding
Ah cool. I never knew that

If I had my way, I''d have all of you shot!


codeka.com - Just click it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.