Région de recherche :

Date :

https://stackoverflow.com › questions › 347949

How to convert a std::string to const char* or char*

If you just want to pass a std::string to a function that needs const char *, you can use .c_str(): std::string str; const char * c = str.c_str(); And if you need a non-const char *, call .data(): std::string str; char * c = str.data(); .data() was added in C++17. Before that, you can use &str[0].

https://stackoverflow.com › questions › 1431576

How do you declare string constants in C? - Stack Overflow

The compile time string concatenation almost selled me on using #defines for strings but I'll stick to const char* for type safety using static where applicable. In short I'll use enum for integer constants and const variables for all the rest.

https://www.gnu.org › software › c-intro-and-ref › manual › html_node › String-Constants.html

String Constants (GNU C Language Manual)

A string constant defines an array of characters which contains the specified characters followed by the null character (code 0). Using the string constant is equivalent to using the name of an array with those contents.

https://en.cppreference.com › w › c › language › character_constant

Character constant - cppreference.com

When used in a controlling expression of #if or #elif, character constants may be interpreted in terms of the source character set, the execution character set, or some other implementation-defined character set.

https://zestedesavoir.com › tutoriels › 755 › le-langage-c-1 › 1043_aggregats-memoire-et...

Les chaînes de caractères - Le langage C - Zeste de Savoir

Les chaînes de caractères qui fonctionnent sur ce principe sont appelées null terminated strings, ou encore C strings. Cette solution a toutefois deux inconvénients : la taille de chaque chaîne doit être calculée en la parcourant jusqu’au caractère nul ;

https://en.cppreference.com › w › cpp › string › basic_string

std::basic_string - cppreference.com

concatenates two strings, a string and a char, or a string and string_view (function template)

https://www.geeksforgeeks.org › why-is-conversion-from-string-constant-to-char-valid-in...

Why is Conversion From String Constant to 'char*' Valid in C but ...

Conversion From String Constant to char*. In C, it’s permissible to assign a string constant to a ‘char*’ variable and the reason behind it is historical. When C was developed, the ‘const’ keyword didn’t exist, so string constants were just ‘char []’.

https://en.cppreference.com › w › cpp › string › basic_string › c_str

std::basic_string<CharT,Traits,Allocator>:: c_str - Reference

const CharT* c_str()const; (noexcept since C++11)(constexpr since C++20) Returns a pointer to a null-terminated character array with data equivalent to those stored in the string. The pointer is such that the range [c_str(),c_str()+ size()] is valid and the values in it correspond to the values stored in the string with an additional null ...

https://www.geeksforgeeks.org › constants-in-c

Constants in C - GeeksforGeeks

The constants in C are the read-only variables whose values cannot be modified once they are declared in the C program. The type of constant can be an integer constant, a floating pointer constant, a string constant, or a character constant. In C language, the const keyword is used to define the constants.

https://openclassrooms.com › fr › courses › 19980-apprenez-a-programmer-en-c › 7672681...

Apprenez à programmer en C - OpenClassrooms

La fonction prend un paramètre de type const char* . Le const( qui signifie constante) fait que la fonction strlen "s'interdit" en quelque sorte de modifier votre chaîne. Quand vous voyez un const , vous savez que la variable n'est pas modifiée par la fonction, elle est juste lue.