STL std::string, char*, const char*, and string literals in C++ | Modern Cpp Series Ep. 112

Поділитися
Вставка
  • Опубліковано 16 лис 2024

КОМЕНТАРІ • 28

  • @pyajudeme9245
    @pyajudeme9245 Місяць тому +1

    Awesome channel! I started to use C++ in Cython a while ago, and your videos have helped me a lot! Thx!

    • @MikeShah
      @MikeShah  Місяць тому

      Cheers -- I'm happy to hear that!

  • @thestarinthesky_
    @thestarinthesky_ Рік тому +4

    @17:12 we might want to do this to get the address . std::cout

  • @yvickmiossec6536
    @yvickmiossec6536 Рік тому +7

    Mike’s stuff is excellent. I have learnt many, many things from his videos. Very surprised at the number of views: IMHO, this channel is a fantastic ressource for the programming enthousiast. Thank you Mike !

    • @MikeShah
      @MikeShah  Рік тому

      Cheers, thank you for the kind words 🙂

  • @gandab
    @gandab Рік тому +1

    Nice and simple explanation for new programmers going into C++ especially with no C experience beforehand. I noticed that you can get the first char address with something like const char* first_char = the_string_var.data(); Then cout &first_char.

  • @nematjonabdulloev3568
    @nematjonabdulloev3568 Рік тому +3

    Nice explanation.
    How to setup vim for c++ development?

    • @MikeShah
      @MikeShah  Рік тому

      Cheers! My VIM is pretty plain, but this may help for larger longer term projects: ua-cam.com/video/IR6pfkqjbw8/v-deo.html

  • @zdspider6778
    @zdspider6778 Рік тому +3

    13:46 Could you explain a bit more in detail what "extern "C"" does? Because "extern" is used to tell the compiler that the variable is located in a different translation unit, so it compiles it, then the linker is supposed to look for it _after_ the compiler is done. So what is "C" supposed to be? A string? There's a special rule for it or something?

    • @MikeShah
      @MikeShah  Рік тому +1

      The "C" part tells the compiler not to mangle the name and match the C naming convention when loading functions. This is useful when building libraries that may be called from C code.

  • @JaswinderSingh-dz1ui
    @JaswinderSingh-dz1ui Рік тому +1

    Hi Sir, Please Explain using namespace std::string_literals or using namespace std::literals

    • @MikeShah
      @MikeShah  Рік тому

      May consider that for a future video -- cheers

  • @TheOldRoots
    @TheOldRoots 8 місяців тому +1

    Hello Mike! Do you have any video that talks about handling very large numbers in c++? Like if I want to store 10000! (which cannot even be stored in an unsigned long long) and use it in some computation for example

    • @MikeShah
      @MikeShah  8 місяців тому +1

      I don't at this time -- that's a nice idea, and I remember doing this long ago for a homework assignment :)

  • @safatkhan676
    @safatkhan676 26 днів тому +1

    Hey Mike! Referring to 16:52 :
    If s.data() implies some function return from the string class, is that not a temporary r-value to start with?

    • @MikeShah
      @MikeShah  25 днів тому +1

      s.data() is returning the internal pointer to the string class. Since that memory has a location, it is an lvalue (i.e. it's not something temporarily constructed.)

    • @safatkhan676
      @safatkhan676 25 днів тому +1

      @@MikeShah Thanks a lot! I completely misunderstood what s.data() was actually doing. Didn't realise it was literally giving us the pointer to the start of the string. Someone needs to RTFM! Haha! Thanks for all your content.

    • @MikeShah
      @MikeShah  25 днів тому

      @@safatkhan676 cheers! No worries at all

  • @moatasemelsayed6226
    @moatasemelsayed6226 Рік тому +2

    Hey mike could we have a session about how to trace the allocation of memory during runtime for every method

    • @MikeShah
      @MikeShah  Рік тому

      Yup, will likely come in my C programming series first then a variation using C++ in this series next.

    • @moatasemelsayed6226
      @moatasemelsayed6226 Рік тому +1

      Thank you for your precious effort it is very helpful 😍

  • @ughadunk
    @ughadunk Рік тому +1

    Just uniform initialize that string already.

  • @__hannibaal__
    @__hannibaal__ Рік тому +1

    If we need Japanese char how to use std::string for jp_char like : std::Jstring . Thanks.

    • @MikeShah
      @MikeShah  Рік тому +1

      I believe Japenese characters would be found in UTF-8. Depending on if there is one character or two characters to represent the character set, that might vary whether std::string works with Japanese characters -- and also note your terminal needs to be able to output the UTF-8 encoded characters..