How Strings Work in C++ (and how to use them)

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ส.ค. 2017
  • Patreon ► / thecherno
    Instagram ► / thecherno
    Twitter ► / thecherno
    Slack ► slack.thecherno.com
    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 ► www.cplusplus.com/reference/st...
    Pointers ► • POINTERS in C++
    Arrays ► • Arrays in C++
    Series Playlist ► • C++
    Gear I use:
    -----------------
    BEST laptop for programming! ► geni.us/pakTES
    My FAVOURITE keyboard for programming! ► geni.us/zNhB
    FAVOURITE monitors for programming! ► geni.us/Ig6KBq
    MAIN Camera ► geni.us/t6xyDRO
    MAIN Lens ► geni.us/xGoDWT
    Second Camera ► geni.us/CYUQ
    Microphone ► geni.us/wqO6g7K

ความคิดเห็น • 427

  • @Brotcrunsher
    @Brotcrunsher 6 ปีที่แล้ว +482

    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!

    • @TheCherno
      @TheCherno  6 ปีที่แล้ว +337

      Yes, you're right. I should have defined it as *char name[] = "Cherno";* in that example.

    • @forest_grow
      @forest_grow 6 ปีที่แล้ว +8

      Please what is the difference between:
      char* a = "Cherno";
      a[2] = 'a';
      output is:error
      and
      char* a = "Cherno";
      a = "Charno";
      std::cout

    • @forest_grow
      @forest_grow 6 ปีที่แล้ว +4

      Yeah, I saw that the address is changing sorry

    • @mariogalindoq
      @mariogalindoq 6 ปีที่แล้ว +51

      Стефан Рибак In the second alternative, you aren't changing the memory the pointer "a" points to. You are changing the value of the pointer "a" to point to other place that contains other char string (with the same letters). I think this could seems difficult, so I'll try to explain better:
      char *a = "Cherno"; creates a pointer "a" that points to a memory that contains the letters "Cherno".
      a = "Cherno"; change the value of the pointer "a" to point to other memory that also contains the letters "Cherno".
      So, later you can also do
      a = "A big string like this"; and it will work too, because "a" will point now to a new memory. The old memories with "Cherno" will remain unchanged somewhere in memory.

    • @forest_grow
      @forest_grow 6 ปีที่แล้ว +2

      Mario Galindo oh thank you for explaination) it helps me a lot in the future)

  • @danilivanov6262
    @danilivanov6262 4 ปีที่แล้ว +112

    Replacing my Netflix binging with TheCherno binging. Loving these videos!

    • @haru02w89
      @haru02w89 10 หลายเดือนก่อน +1

      That's what I'm doing. A lot more useful content here than in Netflix

    • @jayocaine2946
      @jayocaine2946 9 หลายเดือนก่อน

      ​@haru02w89 it's not useful if you don't actually go and code a lot

    • @whoeverofhowevermany
      @whoeverofhowevermany 6 หลายเดือนก่อน

      bing bing. bing ing.

    • @zanagi
      @zanagi 6 หลายเดือนก่อน +1

      C++ is addicting af when I watch this guy

  • @Steven-tw7iz
    @Steven-tw7iz 6 ปีที่แล้ว +348

    This is hands down the best c++ series on youtube. Very professional and informational, amazing job once again Yan! Your videos are fantastic!

    • @nighma
      @nighma 6 ปีที่แล้ว +15

      Do you sell his videos? :D
      (joke)

    • @ruf1o2o
      @ruf1o2o 6 ปีที่แล้ว

      damn right!

    • @rcookie5128
      @rcookie5128 6 ปีที่แล้ว +3

      Agreed!

    • @jorgejarai
      @jorgejarai 4 ปีที่แล้ว +3

      It definitely is. Yan is the kind of programmer I'm aspiring to become. He's such knowledgeable and proficient (he's also pretty handsome 😳)

    • @bringiton2100
      @bringiton2100 3 ปีที่แล้ว

      I would you said "eres un bebe precioso" (You are a precious baby Cherno) hahaha

  • @Gilpow
    @Gilpow 6 ปีที่แล้ว +129

    10:13 Note that in the console output, there are 25 garbage characters after "Cherno".
    Exactly the number of bytes in memory, after that strings, before a "00" byte is reached ^^

  • @TalisBarbalho
    @TalisBarbalho 6 ปีที่แล้ว +26

    Even when you say that you were just "mumbling", you still share so much knowledge with us. Thank you for that. Just keep releasing the videos that are easier for you to produce and leave the others for when you have time. Looking forward for the really deep engine programming. Many thanks for the video

  • @danielketcheson1965
    @danielketcheson1965 ปีที่แล้ว +2

    Your explanation on how you learn best; being taught what works vs how it works
    makes my inquisitive mind tingle with joy. Even makes me trust your content all the more.
    I feel this style is empowering to the individual who is seeking to utilize and transfer knowledge to any persons interested.

  • @kacperozieblowski3809
    @kacperozieblowski3809 6 ปีที่แล้ว +10

    This series is sooo well made, keep making it please

  • @jmac217x
    @jmac217x ปีที่แล้ว +3

    Every time I think I know a little about something I find out how little I know! Thanks Cherno 5 years later your knowledge is still invaluable. The Discord is a great resource

  • @mkdeviphone
    @mkdeviphone ปีที่แล้ว

    Like your style explaining stuff down to memory level! And you do it so direct! Genius!

  • @justicefor4ll
    @justicefor4ll 5 ปีที่แล้ว +6

    Missed my lecture today on strings, thanks for this! :)

  • @j4n0w5k1
    @j4n0w5k1 4 ปีที่แล้ว +2

    Love your stuff, I am a student learning C++, and your channel is my go to when I need help

  • @KandMe1
    @KandMe1 3 ปีที่แล้ว +1

    Well just to say my thoughts are your doing this really well by laying out this ground work for reference once you drop something of a really meaty project. Thanks for this it will help a lot knowing I can go back and go through these at any time. Well done.

  • @Krokoklemmee
    @Krokoklemmee 6 ปีที่แล้ว +11

    neat video, I just want to point out a few things that weren't *entirely* correct:
    1.) UTF-16 is not a 16-bit fixed-width encoding. It simply works in *blocks* of 16-bit code units, where a character can be made up of one or two code units.
    2.) wchar_t is not guaranteed to be 2 bytes wide, that's only the case on Windows (on most unix-like OS's for example, a wchar_t is 4 bytes long). That's why we got std::u16string :P
    3.) Modifying a value previously declared "const" is not "totally fine", it's undefined behavior

    • @TheCherno
      @TheCherno  6 ปีที่แล้ว +11

      I addressed most of these in my video on string literals. :)

  • @CRBarchager
    @CRBarchager 6 ปีที่แล้ว +1

    I haven't played around with c++ since the last 90's (Borland) and use C# these days in my day to day work. This series of c++ gives a great insight how far the language have progressed since then and is a real joy to watch and learn.
    You clearly know your way around the language and you do it way better than anyone else I've seen through the years on youtube. If you want to make 1, 2, 3 or more videos a week is up to you but I don't mind more with the quality you put out.

    • @mytech6779
      @mytech6779 6 ปีที่แล้ว

      I had heard similar from many folks, but as I recently started to look into learning a systems capable language comparing various advantages of each(both direct features and meta stuff like maturity, guide books, and employment) I found I kept coming back to C++.
      C++ was ISO standardized in 1998, then a major update in 2011, with minor additions in 14 a few in 17 and several predicted for 2020. I also discovered that "C/C++" is an incorrect term as the ISO C standard is not synchronized with the C++ standard; C++ is an independent fork from before C89.
      Many negative C++ opinions seem to be based on experience [or for younger folk repetition of urban legends] from the early 1990s. (partly exaggerated by articles and postings created by Sun's heavy Java marketing efforts and stubborn old timer C devs) Certainly not helped by education curricula that frequently uses 20 year old books and compilers, and a teacher that has been out of the commercial game for so long their "best practices" have been deprecated.

  • @RandomGuyyy
    @RandomGuyyy 6 ปีที่แล้ว

    I love this style of video where the speaker has a loose conversational style. They naturally wander into tangential subject matter because many things are related. So they feel like they are rambling but I reckon it's just a natural traversal of the subject.
    Excited to hear mention of a new series!

  • @Trainfan1055Janathan
    @Trainfan1055Janathan 3 ปีที่แล้ว +15

    What does it mean when there are double quotes with no text in them?
    For example, in this one script for a tram in a train simulator I play, there's a line of text that reads:
    string destination = "";
    (I'm trying to learn how trains are scripted in this game, so I can make my own scripts.)

    • @sacripudding4586
      @sacripudding4586 3 ปีที่แล้ว +20

      its just making an empty string with nothing in it but also making sure it isn't null so if something tried to get that destination it wouldn't just crash the program when it doesn't get a string out of it.

    • @jukit3906
      @jukit3906 2 ปีที่แล้ว +7

      well it would just put the '\0' at the memory location

    • @jukit3906
      @jukit3906 2 ปีที่แล้ว +2

      to be more precise the const char pointer would point at a char of value 0

  • @krec348
    @krec348 6 ปีที่แล้ว +3

    Keep that style of videos, they have are awesome! Magnific

  • @Usammityduzntafraidofanythin
    @Usammityduzntafraidofanythin 2 ปีที่แล้ว +1

    The number of asides are BRUTAL in this video

  • @procactus9109
    @procactus9109 6 ปีที่แล้ว +8

    These videos are definitely improving my skills. And it will help to understand more of what Bisqwit code(a little).
    Cheers Dude :)

  • @daddy9004
    @daddy9004 5 ปีที่แล้ว +3

    I cant express how valuable those videos are. Thank you so much for doing this!

  • @advitiayanand5974
    @advitiayanand5974 5 ปีที่แล้ว +1

    I wanna say you're videos have been the most helpful and informative.
    Seriously man. Keep at it!

  • @IsaacAsante17
    @IsaacAsante17 5 ปีที่แล้ว

    Cherno, I'm your new fan. Your C++ videos are gems.

  • @CacheTaFace
    @CacheTaFace 4 ปีที่แล้ว

    These videos are so helpful, you are the MAN!

  • @pball1000
    @pball1000 5 ปีที่แล้ว

    Good stuff. VERY helpful. Thank you! Im learning so much

  • @leixun
    @leixun 4 ปีที่แล้ว +50

    *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

    • @takitachibana7717
      @takitachibana7717 3 ปีที่แล้ว

      it doesn't work if my code is like -
      {
      char* name = "cherno";
      std::cout

    • @MrCoder-xj9yi
      @MrCoder-xj9yi 3 ปีที่แล้ว +1

      @@takitachibana7717 See the pinned comment

    • @takitachibana7717
      @takitachibana7717 3 ปีที่แล้ว

      @@MrCoder-xj9yii already know.Thanks anyway man.

    • @forbidden-cyrillic-handle
      @forbidden-cyrillic-handle ปีที่แล้ว

      ​@@takitachibana7717 It works for me, but I'm on Linux with gcc compiler. But if I try to change it I get segmentation fault, becase the memory referenced is read only memory protected from writting to it.

  • @DineshGowda24
    @DineshGowda24 5 ปีที่แล้ว

    I like how u explain c++ and enjoy it. C++ is one the best lovely languages if we understood it properly. Keep up the good work. Just saw ur playlist on c++ gonna watch it all today. Hope u upload more c++ videos.👌👌👌👌👌 Top notch stuff

  • @v-for-victory
    @v-for-victory 2 ปีที่แล้ว

    Very good explaining and a great series.

  • @rcookie5128
    @rcookie5128 6 ปีที่แล้ว +3

    and again expanded my knowledge on such basic concepts like string. I feel enlightened!

    • @rcookie5128
      @rcookie5128 6 ปีที่แล้ว

      so excited for our own data structures!!

    • @ananthteja6357
      @ananthteja6357 10 หลายเดือนก่อน

      kk bro

  • @jerfersonmatos28
    @jerfersonmatos28 4 ปีที่แล้ว

    Wow, very clear explanation

  • @tokyoanimeseven
    @tokyoanimeseven 5 ปีที่แล้ว

    Bro Your Explanation Is Just Awesome.

  • @sallaklamhayyen9876
    @sallaklamhayyen9876 2 ปีที่แล้ว

    Brilliant explanation thank you so much and please continue
    we need content about C++ Data Structure STL and more about critical parts in C++

  • @Djzaamir
    @Djzaamir 6 ปีที่แล้ว

    great video as always @Cherno

  • @reean6342
    @reean6342 4 ปีที่แล้ว

    another EXCELLENT video!

  • @mathewmccloskey8242
    @mathewmccloskey8242 6 ปีที่แล้ว +1

    Great video, as always :)

  • @obong5241
    @obong5241 4 ปีที่แล้ว

    The best C++ series on TH-cam.

  • @tarik9563
    @tarik9563 4 ปีที่แล้ว +1

    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.

  • @TheStapleZ
    @TheStapleZ 6 ปีที่แล้ว

    Please keep making these videos!! :)

  • @Nicolas-gq9vu
    @Nicolas-gq9vu 6 ปีที่แล้ว

    Good work for this video!

  • @stephenjames5745
    @stephenjames5745 3 ปีที่แล้ว

    Thanks for the awesome videos!

  • @yasoda1
    @yasoda1 4 ปีที่แล้ว

    Yan, you are a Godsend!

  • @diribad
    @diribad 4 ปีที่แล้ว

    The Cherno is a god sent gift lol

  • @OFaruk58
    @OFaruk58 6 ปีที่แล้ว +4

    Amazing video's
    Just noticed the "Gear I use"
    All off them are freaking expensive lol

  • @onurucar1112
    @onurucar1112 4 ปีที่แล้ว

    super helpful!! thanks

  • @petarsmilajkov9431
    @petarsmilajkov9431 6 ปีที่แล้ว +2

    Great videos man. Needed to brush up on C++ as I haven't used it in years, and I've been 2X-ing your videos all day. Now on 32! Matrix upload-style. What app do you use for screen recording if I may ask? Thanks and keep the videos coming!

  • @zhaadd
    @zhaadd 2 ปีที่แล้ว

    me casually switching tabs each time his face pops up. i luve the code ohk. keep the great content coming its better than uni omg

  • @ahumanzr
    @ahumanzr 3 ปีที่แล้ว +2

    I got a nice warning at 5:54 (removing "const")
    "Conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]"
    Essentially, non-const char pointers are deprecated in c++ 11

    • @ahumanzr
      @ahumanzr 3 ปีที่แล้ว

      (Warnings don't break your code. In fact, they have absolutely no effect in your program. It's only a little message that says something is a little off with your code, but it will still run)

  • @ananthteja6357
    @ananthteja6357 10 หลายเดือนก่อน

    Amazing video :)

  • @nighma
    @nighma 6 ปีที่แล้ว +1

    Thanks! That's great! Hope to see more next. There are already a bunch of "that will be explained in another video" reference in this serie. I can't wait! Thank you

  • @Vego1274
    @Vego1274 6 ปีที่แล้ว

    I really like Your videos :)
    You should also make a video about C++/CLI and how to use it :)
    It might be very useful for people who want to use C# from C++.
    Anyway, good work ^^

  • @kristinaraciukaityte3451
    @kristinaraciukaityte3451 6 ปีที่แล้ว +2

    I usually dont curse, but this..... this is fcking amazing.

  • @user-in7ez5zf4p
    @user-in7ez5zf4p 4 ปีที่แล้ว

    really good thank you

  • @dubtron6667
    @dubtron6667 4 ปีที่แล้ว

    Great video.

  • @burzonsgames1903
    @burzonsgames1903 2 ปีที่แล้ว

    I love you bro, u solved my problem

  • @eliasabdulbaaki6090
    @eliasabdulbaaki6090 2 ปีที่แล้ว

    This dude is very good.

  • @sanyi_derda
    @sanyi_derda 3 ปีที่แล้ว +6

    4:06 Slight mistake: UTF doesn't work like that. UTF-16 doesn't mean we have 2^16 different characters. UTF is variable length. There are way more possibilities than 2^16.

  • @jeffzz111
    @jeffzz111 2 ปีที่แล้ว

    thank you!

  • @mattgraves3709
    @mattgraves3709 3 ปีที่แล้ว

    I hope that you get to doing data structures and possibly an analysis ot algorithms.
    I am using your videos to implement the Algorithms outlined in Robert Sedgewick's textbook by the same name. Currently in Java for the 4th edition, the 3rd has C++ implementations, however it was written in 98. so I am trying to redo it with a more modern idiomatic C++.
    Then smartly use this with Android to prove and measure the performance boost.
    So far so good man, I am getting the language easily with your help

  • @alltheway99
    @alltheway99 4 ปีที่แล้ว +6

    when passing an object as argument, copy is made on stack, 17:18

  • @RoshanPradhan2
    @RoshanPradhan2 3 ปีที่แล้ว +2

    Your eyes radiate light!

  • @Lesgunia
    @Lesgunia 6 ปีที่แล้ว

    Yeay Discord! That would be so great! I already have other courses that use discord so I did not want to download or join slack. But I would for sure join a discord group. :)

    • @gavinw77
      @gavinw77 6 ปีที่แล้ว

      What's wrong with having both discord and slack - they are actually different tools.

    • @Lesgunia
      @Lesgunia 6 ปีที่แล้ว

      If you ask me, nothing. I just personally don't like to use many tools for the same reason. :)
      Also as far as I know both are live now, so if you like to use both, you can have the benefit of joining both conversations.

  • @Destrio_Fury
    @Destrio_Fury 2 ปีที่แล้ว +3

    That transparancy is the reason I prefer C++ above Java, of course it's easy to do in Java. But u will forget after some time why u did it, but C++ code will make sure u understand everything before anything works 🤣🤣

  • @HarryBallsOnYa345
    @HarryBallsOnYa345 5 ปีที่แล้ว

    Have you thought about doing a video on regular expressions in c++??

  • @matteusberg9091
    @matteusberg9091 5 ปีที่แล้ว +1

    String is a type of char array.
    You should pass a string by reference into a function.
    When declaring a string and you want to use the + operator in order to add two const char arrays togehter, use std::string() on the first char array.
    declaring a variable as const is simply a promise that could be broken, but shouldn't.
    Got it!

  • @ashishmathewabraham7278
    @ashishmathewabraham7278 5 ปีที่แล้ว +2

    I really like the fact that you show how the memory view in Visual studio works , which it makes so much clear . I wanted to see this memory view in Xcode . Do you happen to know if the memory view is available in Xcode?

    • @anuglybug4473
      @anuglybug4473 3 ปีที่แล้ว +1

      while using a breakpoint:
      in the ‘debug window pane’
      right mouse click on the variable of interest -> in the drop down menu that opens,
      left mouse click on ‘ view memory of “...variable...” ‘
      ( as is demonstrated in ‘visual studio’ )
      does anyone know how to get a ‘tool tip’ to display of the address of a variable while the mouse cursor is over the variable ???
      & is there a way to enter the variable name into a text box that then displays the variable’s values in the memory window pane ?
      [as an alternative to the solution provided above]

  • @MMNayem-dq4kd
    @MMNayem-dq4kd ปีที่แล้ว

    Thank you

  • @xristosbart8217
    @xristosbart8217 6 ปีที่แล้ว +5

    What was that about? I mean the thing about the new series.
    I guess heap allocation, polymorphism and constructor initialization is what's left untill we can get to data stractures, right?

  • @zakesters
    @zakesters ปีที่แล้ว

    You can output strings with just now, though I think you still need to get all the nifty methods.

  • @Im10105656
    @Im10105656 6 ปีที่แล้ว +37

    When you do char* name = "Cherno" don't you create a string literal that's read-only? Is name[2] = 'a' is undefined behavior or not?

    • @TheCherno
      @TheCherno  6 ปีที่แล้ว +42

      Yes, you're right. I should have defined it as *char name[] = "Cherno";* in that example.

  • @1234feng
    @1234feng ปีที่แล้ว

    Thank you ! Can you talk about c++ std::wstring performance slow and how to improve performance ?

  • @azizas9366
    @azizas9366 6 ปีที่แล้ว +1

    love this channel.

  • @majesticmack
    @majesticmack 6 ปีที่แล้ว +3

    I already know c++. I just watch these vids just to see Yan haha

  • @chainonsmanquants1630
    @chainonsmanquants1630 3 ปีที่แล้ว

    Thanks

  • @nemesisanims7401
    @nemesisanims7401 3 ปีที่แล้ว

    did you make a video on stack guards, the thing you talked about in this video?

  • @Idlecodex
    @Idlecodex 4 ปีที่แล้ว

    Oh Man.... This is like Game Of Thrones! a Marathon I can only leave if I fall asleep...! Damn it!

  • @TheSpartan989
    @TheSpartan989 6 ปีที่แล้ว +2

    When you were talking about ways to add onto strings, could you use the .append method as another way to add onto the string?

    • @xrafter
      @xrafter 4 ปีที่แล้ว

      Append is just a heap thing

  • @1vor12dokus8
    @1vor12dokus8 2 ปีที่แล้ว

    thanks for the vid and all of them, still invaluable years later. One little remark to 13:36 and the overload of the "

    • @jiaxiin2769
      @jiaxiin2769 3 หลายเดือนก่อน

      Yes, no need to add header in 2022

  • @Josifer4GAppFire
    @Josifer4GAppFire 6 ปีที่แล้ว +43

    I still don't understand how a char* can be a string.. I thought a pointer is just a memory address

    • @vitorkiguchi4670
      @vitorkiguchi4670 6 ปีที่แล้ว +57

      the way the char* and char[] strings work in C/C++ is so: the text inside the double quotes is broken up into individual characters, and those characters are stored in a char array, with a '\0' as the last element of the array.
      The pointer itself points to the adress of the first element of the array, the beggining of the string, while the end of it is marked with the '\0' char.

    • @aryesegal1988
      @aryesegal1988 6 ปีที่แล้ว +25

      the type of a quoted string literal, such as "Cherno", is actually char*. That is, a quoted string literal IS actually an address. An address of what? It is the address of the first character in the string. That means that the entire construct "Cherno" - including the double quotes - actually equals to the address of the first character, 'C' in this case.
      The reason for this is that the compiler stores the string literal ("Cherno") in memory, and it only remembers the address of the strings' beginning character ('C' in our case.) All the program needs to actually use this string is use the address of its first character. The terminating null character '\0' takes care of marking the end of the string literal.

    • @ArachnosMusic
      @ArachnosMusic 3 ปีที่แล้ว +7

      @@vitorkiguchi4670 I know this is an old comment, however you say the following: 'The pointer itself points to the address of the first element of the array.' Shouldn't it be the case that this pointer IS the memory address for that first element? And if so, why then does cout

    • @piaIy
      @piaIy 3 ปีที่แล้ว +2

      @@ArachnosMusic operator

    • @abderezakabidi4510
      @abderezakabidi4510 3 ปีที่แล้ว

      @@vitorkiguchi4670 I read your answer and i think you can help me to solve this error.
      So, I got an error when I run the code below .
      ////
      char* name="learn";
      std::cout

  • @alexandreengelmann879
    @alexandreengelmann879 5 ปีที่แล้ว

    Excelent series. I have learn a lot with these videos. One question, that i'm in trouble:
    In visual studio 2017 if you don't put the const word before "char* name " it won't compile. It gives error C2440 - initializing cannot convert from 'const char [7] to 'char*'. But if I use other ide it work. How can I fix this?

  • @arnmazing3156
    @arnmazing3156 5 ปีที่แล้ว

    Dang here I was hoping you would expand more on c-strings and how to manipulate them like using strstr(); or strcmp(); without using the string library

  • @oxamic9953
    @oxamic9953 11 หลายเดือนก่อน

    thanks you

  • @mattjohnson9453
    @mattjohnson9453 6 ปีที่แล้ว

    I think it's also important to note that characters themselves are just numbers; putting single quotes around a character makes it evaluate to a number, the only reason it prints to form text is that single byte numbers are (mostly) interpreted as such. There isn't a whole lot of difference between char txt = 'a'; and int8_t num = 97;

    • @mytech6779
      @mytech6779 6 ปีที่แล้ว

      A traditional terminal screen or printer interprets all bytes as part of a character set. Actual numeric values such as integers must be converted to the corresponding characters before being sent to the screen. Thus the need for cout or printf formatting functions.

    • @justind6983
      @justind6983 6 ปีที่แล้ว

      hey says this in a previous video :)

  • @h.hristov
    @h.hristov 6 ปีที่แล้ว

    This style of videos is alright :)

  • @b0606089
    @b0606089 2 ปีที่แล้ว

    Please make a video on wide string

  • @codewithfelix3940
    @codewithfelix3940 2 ปีที่แล้ว

    this is some fresh breath of c++ here ...

  • @DanielLiljeberg
    @DanielLiljeberg 6 ปีที่แล้ว

    What tis the best platform independent way to handle strings that should bve able to contain letters outside of standard ASCII. Like ü or å, ä and ö etc? I find a lot of library specific string types like WideStrings or UnicodeString from Embarcaderos VCL for instance but if one does not want to tie the program to a specific library I haven't found a very good solid answer of what to use.

  • @pavanrameshghate5416
    @pavanrameshghate5416 3 ปีที่แล้ว +1

    apart from the study did you pick your channel name from the Pacific Rim movie(cause one of the yager names in that one is cherno Alpha)

  • @wasit-shafi
    @wasit-shafi 5 ปีที่แล้ว

    nice video.....can u tell me which editor u r using

  • @ppoplawski
    @ppoplawski 6 ปีที่แล้ว

    In the example at 15:00 i've also found a way that you can just explicitly cast the " hello!" const char* to std::string (like "Cherno" + (std::string)" hello!";). Is it also a way you would recommend to do concatenation in C++? In other words - are there any disadvantages 'under the hood' while using this method?

    • @touchdepp4507
      @touchdepp4507 ปีที่แล้ว

      Don't use C-style casts in C++ programming. C-style casts are the most dangerous ones.

  • @93davve93
    @93davve93 6 ปีที่แล้ว +32

    Great videos, but you should consider getting a lav mic to boost the audio quality. It is a bit echoey...

    • @LucidStew
      @LucidStew 6 ปีที่แล้ว +5

      Room acoustics. Also explains why his voice sounds relatively shallow in the mid-range and slightly boosted on the low end. He could fix a fair amount of that just by turning at a slight angle to the wall or putting up something textured on the wall in front of him.

  • @BeatSmokerFactory
    @BeatSmokerFactory 6 ปีที่แล้ว +1

    Thanks for your awesome content, i watch you since the rain java project and learned so much from your videos, thank you.
    One question: i heard a joke about c++ strings beeing really slow when appending something to the string, because you do not know the length of the string and have to go through the whole thing in order to get its length and know where to append to.
    Are there other string classes where the length is stored or is this class still typically used ?

    • @Steven-tw7iz
      @Steven-tw7iz 6 ปีที่แล้ว

      the c++ string class does give you functionality to get the length of the string. If you use a char* or a char[] you need to keep track of the length yourself, and that would speed up any slowdown that could occur by needing to loop over the whole string to get the length. I hope this helps :)

    • @BeatSmokerFactory
      @BeatSmokerFactory 6 ปีที่แล้ว

      yes, but the function to look up the length is a while loop until you reach the null character, isn´t it?

    • @Steven-tw7iz
      @Steven-tw7iz 6 ปีที่แล้ว

      oh it might be. I didn't think about that. I'm sorry. I don't know the std library that well. I usually make my own data structures unless I'm making something quick ad dirty. so I never took the time to learn exactly what happens under the hood. but if that is the case I would suggest to make your own string class that would suit your needs and keep track of the length automatically so it speeds up that operation. :)

    • @TheCherno
      @TheCherno  6 ปีที่แล้ว +4

      It is for raw char pointers or char[], however std::string has a member (an int) which keeps track of the size, so no counting necessary.

  • @psyberpirate
    @psyberpirate 2 ปีที่แล้ว

    Do you have a camera setup video, this video has a distinct look to it

  • @TheRandomJacob
    @TheRandomJacob 6 ปีที่แล้ว

    Great video! I have a question: why aren't you using using namespace std; ?

  • @brakpseudonimu236
    @brakpseudonimu236 ปีที่แล้ว

    So what's the difference between char* and other pointers? As I understand, it's just a pointer like any other pointer, and the memory allocation and writing is done by the double quotes function that returns the pointer, right?

  • @rbcm1
    @rbcm1 4 ปีที่แล้ว

    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?

    • @xrafter
      @xrafter 4 ปีที่แล้ว

      @Artem Katerynych
      Std ::string are allocated in the heap

  • @xthebumpx
    @xthebumpx 6 ปีที่แล้ว +3

    Discord would be great

  • @ArachnosMusic
    @ArachnosMusic 3 ปีที่แล้ว

    Shouldn't it be the case that the pointer 'name' is the memory address for the first element of the const char[] array which is "Cherno"? And if so, why then does cout

  • @mm1979dk
    @mm1979dk 6 ปีที่แล้ว +2

    15:00 you could write it even simpler using literals (C++14), like this:
    auto hello = "Hello"s + " world!";

  • @killakill8731
    @killakill8731 6 ปีที่แล้ว +2

    why do not use 'using namespace std; ' does it has something to do with performance ?
    I already researched but I didn't quite understand.

    • @alexhorejsi6287
      @alexhorejsi6287 5 ปีที่แล้ว +2

      From what I have heard, 'using namespace std' is often considered bad practice. Apparently there is so many classes and functions in that namespace that it is not unlikely that you will accidentally name a function or class the same as something in the std namespace. I have heard from several developers that they have spent a lot of time debugging code that used 'using namespace std' due to name conflicts

  • @rylanjohnson9049
    @rylanjohnson9049 ปีที่แล้ว

    Might be confusing at first just understand that the reason std::cout prints the string instead of the memory address is just because it interprets it as a C-style string instead of printing the address

  • @nathancwatkins
    @nathancwatkins 3 ปีที่แล้ว +1

    at 13:10, when he says you can change the string (a const char array) by doing "an implicit cast to a char pointer" if we wanted to manipulate the array. Could someone clarify what he means here. I really appreciate it.
    p.s Love the series! Sorry if im a noob, learing c++ at a cc -