473,804 Members | 3,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string v.s. basic_string

Hello everyone,
I would like to learn some experiences about when should we use
std::basic_stri ng and when should we use std::string?

I learned some Hello World level samples and now want to listen to
your practical experiences. :-)
thanks in advance,
George
Nov 20 '07 #1
5 3053
George2 wrote:
I would like to learn some experiences about when should we use
std::basic_stri ng and when should we use std::string?

I learned some Hello World level samples and now want to listen to
your practical experiences. :-)
I almost never had to use 'basic_string'. 'std::string' is a typedef
for 'std::basic_str ing<char ...>' (where ... represents some stuff
related to 'char'). If you deal with 'char', 'std::string' is enough.
If you deal with wide char ('wchar_t'), 'std::wstring' is the class.
I heard that Unicode is never well served by either of those, so folks
have their own custom classes for Unicode, I guess.

An example when I did have to use 'std::basic_str ing' is the library
where some functions were specialised for 'char' and 'wchar_t' (they
had to do that to use some non-overloaded functions) and just for the
completion's sake, I added a specialisation for 'unsigned char' and
'signed char' (since those are different from 'char'), and utilised
some casts internally.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 20 '07 #2
George2 wrote:
Hello everyone,
I would like to learn some experiences about when should we use
std::basic_stri ng and when should we use std::string?

I learned some Hello World level samples and now want to listen to
your practical experiences. :-)
thanks in advance,
George
In most cases, we use std::string. I've never used std::basic_stri ng.
Nov 20 '07 #3
Victor Bazarov schrieb:
I heard that Unicode is never well served by either of those, so folks
have their own custom classes for Unicode, I guess.
Is anything planned for the future of C++?

Handling UTF-8 *correctly* is awkwardly difficult, especially since
different characters (not in the C sense of the word) may differ greatly
in length, depending on the type of character.

Some std::utf8string would be really nice.

Greetings,
Johannes

--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerli ch. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathemat ik <47************ **********@news .sunrise.ch>
Nov 20 '07 #4
On Nov 20, 6:26 pm, Johannes Bauer <dfnsonfsdu...@ gmx.dewrote:
Victor Bazarov schrieb:
I heard that Unicode is never well served by either of
those, so folks have their own custom classes for Unicode, I
guess.
Is anything planned for the future of C++?
There will be new types, guaranteed to be UTF-16 and UTF-32.
Handling UTF-8 *correctly* is awkwardly difficult, especially
since different characters (not in the C sense of the word)
may differ greatly in length, depending on the type of
character.
That seems to be a widespread myth. In my experience, it's
rarely a problem. And the same thing is true for UTF-16, and
even UTF-32.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 20 '07 #5
On Nov 20, 12:59 pm, George2 <george4acade.. .@yahoo.comwrot e:
Hello everyone,

I would like to learn some experiences about when should we use
std::basic_stri ng and when should we use std::string?

I learned some Hello World level samples and now want to listen to
your practical experiences. :-)
In general, like Victor said, you have never need to use basic_string
directly. BTW, like guys of microsoft VC newsgroup told you, at least
in Windows world is a common practice to use basic_string with TCHAR
to maintain backward compatibility with older versions of Windows that
don't support unicode strings.
Regards

--
Cholo Lennon
Bs.As.
ARG
Nov 21 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
10783
by: Gaurav | last post by:
Hello, I am using visual c++ 6 and i am having problems with string to work. ******** Here is the program project.cpp********* #include <iostream.h> #include <string> #include "stdafx.h"
7
10631
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using namespace std; : : vector<string>* getTyphoon()
9
8702
by: David Carter-Hitchin | last post by:
Hi, I'm not very experienced with c++ so I'm sure this is something obvious that is easily solved, but for the life of me I can't seem to figure it out. I'd be very grateful for some knowledgeable insight into this. My class Position has a string (private, public - doesn't seem to matter which), which I construct in a member function and wish to return calls from main(). However, although
13
11030
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code below would work... string gsub(const string & sData, const string & sFrom,
11
8804
by: Martin Jørgensen | last post by:
Hi, - - - - - - - - - - - - - - - #include <iostream> #include <string> #include <map> using namespace std; int main() {
2
2638
by: ehui928 | last post by:
hi, everybody I am a newbie in STL. When I compile the following program under gcc4.0, I got a the following errors. I wonder whether the form of list< vector<string> > is correct in STL ? // test.cpp #include <iostream> #include <fstream> #include <vector> #include <string>
10
9070
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use std::string::size or std::string::empty to deal with this condition? Thank you. string s = ""; if (s == ""); if (s.size == 0); if (s.empty());
13
3672
by: arnuld | last post by:
/* C++ Primer 4/e * section 3.2 - String Standard Library * exercise 3.10 * STATEMENT * write a programme to strip the punctation from the string. */ #include <iostream> #include <string>
5
1793
by: Phil Endecott | last post by:
Dear All, For some reason I had got it into my head that std::vector<T>::iterator and std::basic_string<T>::iterator were certain to be T*. I now see that this isn't true. So here's why this matters to me. I have a function that is templated on an iterator type: template <typename Iter>
3
3455
by: banangroda | last post by:
Compilation fails at "line.insert(line.end(), x.begin(), i);" and I can't figure out why. Here is the code: /* 5-1. Design and implement a program to produce a permuted index. A permuted index is one in which each phrase is indexed by every word in the phrase. */
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.