473,473 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Create 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_string 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 3022
George2 wrote:
I would like to learn some experiences about when should we use
std::basic_string 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_string<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_string' 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_string 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_string.
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ästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <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 objektorientierter Datenverarbeitung
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.comwrote:
Hello everyone,

I would like to learn some experiences about when should we use
std::basic_string 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
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
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...
9
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...
13
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...
11
by: Martin Jørgensen | last post by:
Hi, - - - - - - - - - - - - - - - #include <iostream> #include <string> #include <map> using namespace std; int main() {
2
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 ? //...
10
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...
13
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...
5
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...
3
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.