Patreon ►
Instagram ►
Twitter ►
Slack ►
In this video we’re going to talk about how strings work in C++. Strings are groups of characters between double quotes: “this is an example of a string”. We use them to store everything from people’s names to entire paragraphs of text, and we can use them like any other variable. Strings are really just char arrays at the end of the day, and this video takes a deeper look at how they work.
std::string API reference ►
Pointers ►
Arrays ►
Series Playlist ►
Gear I use:
—————–
BEST laptop for programming! ►
My FAVOURITE keyboard for programming! ►
FAVOURITE monitors for programming! ►
MAIN Camera ►
MAIN Lens ►
Second Camera ►
Microphone ►
Nguồn: https://federicobellucci.net/
Xem thêm bài viết khác: https://federicobellucci.net/cong-nghe/
You've made a mistake at 7:03 "[…] otherwise you can just leave it as a char pointer that is totally fine.", implying that it is okay to change a char in that array.
No it is not! That is undefined behavior and leaving a pointer to a String literal non const it deprecated since C++11. You must not change any value of the C-String-Literal!
Thanks for the awesome videos!
You look like elon musk
I actually very much like the way you write your code. I mean: when you write the idea then make affectations and nominations. thank you.
#include <iostream>
int main()
{
char* name = "Cherno";
name[2] = 'a';
}
error: cannot use "const char" value to initialize "char *" entity
Video starts at @5:00
But i thought the string are just pointers so technically you are passing it by reference?
If you add a 0 character to the end of a C# string it messes it up in visual studio when you try to observe the value.
let do it with your activity not saying.
The Cherno is a god sent gift lol
Wow, very clear explanation
super helpful!! thanks
another EXCELLENT video!
Replacing my Netflix binging with TheCherno binging. Loving these videos!
And here I thought I understood strings.
What is that accent? Aussie?
Great video.
Whats your IDE?
char* is a mutable pointer to a mutable character/string.
const char* is a mutable pointer to an immutable character/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion from const char * to char* is deprecated.
char* const is an immutable pointer (it cannot point to any other location) but the contents of location at which it points are mutable.
const char* const is an immutable pointer to an immutable character/string.
Hi Cherno. Where do you stand on using char* instead of string class when coding in C++? Would you always favor the usage of string class or can you think of a reason why not to?
эх буржуйская кодировка
My takeaways:
1. C style string 5:30, and why he uses char* 9:00, because "anything inside a double quote is a char array" 14:10
2. C++ style string 11:04
3. Passing a string to function 16:13, it is better to pass by reference to avoid copy
Love your stuff, I am a student learning C++, and your channel is my go to when I need help
when passing an object as argument, copy is made on stack, 17:18
really good thank you
hi Cherno, I hope you will answer when I wrote char n[ ]={'q', 'e'}; it printed without garbage even I did not implement a null character explicitly. Or is that what you said in the video applies only to the debug mode?
cool
const* char name = "Cherno";
is giving me error : C++ a value of type cannot be used to initialize an entity of type.
Can someone explain this to me?
Cherno!
I copied your code, and you have no errors.
My Code:
main()
{
. . char* name = "Luke";
}
Resulting Error:
E0144: a value of type "const char *" cannot be used to initialize an entity of type "char *"
BUT then I see in your next video that you have to cast (char*) "";
Why don't you have to cast that in this video???
char* name = "Cherno" gives an error message:
A value of type "const char*" cannot be used to initialize an entity of type "char *".
Why does it work in the video?
17:05 Why on the heap if you not using the word new?
The best C++ series on YouTube.
You no longer need to use #include <string> in order to print strings at least that's what happens to me while using CodeBlocks
How is the Qstring arg method used?
Cool! Useful
char* name = "Cherno"; it's a mistake cause a value of type "const char *" cannot be used to initialize an entity of type" char * why doesn't your IDE underline the text with a red line? WHYYY?
These videos are so helpful, you are the MAN!