Josh Posted August 22, 2010 Share Posted August 22, 2010 Here are my imperatives for strings: 1. Ability to add two strings, i.e. Print( a+", "+b ) 2. Ability to insert objects into a map by string. If a mesh is loaded, I want to insert the mesh into a map and be able to retrieve it with the file path. 3. Maximum compatibility on all platforms. The way I see it, I have three options: 1. Use std:strings. 2. Add operators to const char* (if it's possible) 3. Make my own string class. Questions: 1. Is std:string safe to use? Will it work on PS3, Android, etc? 2. Is there a way to automatically convert a string I type into my own string object? i.e.: String s = "Hello"; Thanks. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted August 22, 2010 Share Posted August 22, 2010 Use std::string always, don't even think about using anything else. It will work everywhere, even on my AIX system which is so backwards like an dinosaur (well it's actually so because IBM is a dinosaur) You CAN use char* for extremely speed sensitive system functions, but for user code it's always string which you should use. In system programming you have to use pure C anyway, since every nanosecond of delay matters. That's why it's also good to mix C with C++ code for cases where you know exactly that it's an abstract code and does not fail with infinite amount of data. A game engine is not system programming, so you can use C++ and STL freely. Making an own String class will give you a slower string class, since STL has been insanely well optimized over years. Even a normal QuickSort routine is slower than STL's built-in sorting functions, because STL switches automatically between different sorting algorithms according to the data type and structure you want to sort. It may also be that some C++ compilers are especially optimized to provide maximum performance with STL classes, so no custom classes can ever beat that. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Masterxilo Posted August 22, 2010 Share Posted August 22, 2010 All the std:: (template) classes are guaranteed to work in any complete C++ implementation. Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
Pixel Perfect Posted August 22, 2010 Share Posted August 22, 2010 Agreed, STL is definitely the way to go. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
Roland Posted August 22, 2010 Share Posted August 22, 2010 std::string period. Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Josh Posted August 22, 2010 Author Share Posted August 22, 2010 Please, try not to argue with one another. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Mumbles Posted August 23, 2010 Share Posted August 23, 2010 Funnily enough, only a few days ago I found myself writing a soft of beginners guide to using Leadwerks in a C/C++ environment and one of the topics was strings. Even I was saying to use the std::string and I'm by no means an expert compared to the rest of the posters in this thread. Quote LE Version: 2.50 (Eventually) Link to comment Share on other sites More sharing options...
TylerH Posted August 26, 2010 Share Posted August 26, 2010 boost::string is useful in some cases... Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Roland Posted August 26, 2010 Share Posted August 26, 2010 boost::string is useful in some cases... But then you are forcing users to have Boost installed. Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Canardia Posted August 26, 2010 Share Posted August 26, 2010 They need boost anyway, because LuaBind needs it. The Codewerks installer can have all libs it needs packaged with it, and then its up to the user if he wants to install them, or if he already has them installed. That's how BlitzMax works too, it has all the libs it needs packaged with it. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Roland Posted August 26, 2010 Share Posted August 26, 2010 They need boost anyway, because LuaBind needs it. The Codewerks installer can have all libs it needs packaged with it, and then its up to the user if he wants to install them, or if he already has them installed. That's how BlitzMax works too, it has all the libs it needs packaged with it. Okidoki Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.