Afficher un message
Vieux 22/01/2008, 12h49   #8
Richard Herring
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [NEWBIE] from C string to std::string

In message <5v9ma0F1kefs9U1@mid.individual.net>, Bo Persson <bop@gmb.dk>
writes
>Stefano Sabatini wrote:
>> Hi guys,
>> which is the best way to define a std::string using some C strings
>> (arrays of chars)?
>>
>> Here it is the code:
>>
>> #include <iostream>
>> #include <string>
>>
>> using namespace std;
>>
>> int main(void) {
>> string s;
>> // this won't even compile, since in this case "this is a" and
>> // others string are interpreted like char arrays
>> // s = "this is a" + " string.";

>
>Adding two string literals together is done by the preprocessor. You
>just have to put them adjacent to each other, WITHOUT any operators:
>
>s = "this is a" " string.";
>
>
>Of course, why would you want to do this? :-)
>


One reason might be to embed comments:

std::string angleExpression(
"^\\s*" /* skip leading whitespace */
"([-+]?)" /* exp1 is optional sign */
"\\s*" /* skip whitespace */
"(\\d*)" /* exp2 is integer degrees */
"([:nsew])" /* exp3 is punctuation, maybe quadrant letter */
"(\\d*)" /* exp4 is integer minutes */
"[:']" /* punctuator between min & sec */
"(\\d*)" /* exp5 is integer part of seconds */
"[.,]?" /* maybe there's a decimal part */
"(\\d*)" /* exp6 is fraction of seconds */
"[:"]?" /* may be final punctuation */
"\\s*" /* whitespace */
"([nsew]?)" /* exp7 is quadrant letter */
);

--
Richard Herring
  Réponse avec citation
 
Page generated in 0,05809 seconds with 9 queries