April 19, 2021

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



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://ka-nom.com/

Xem thêm bài viết khác: https://ka-nom.com/cong-nghe/

Related Posts

How to Recover Deleted Data with Stellar Phoenix Windows Data Recovery Professional? Official Video

July 9, 2020

July 9, 2020

Watch the updated video here @ ** Free Download: ** Buy Now: Stellar Phoenix Windows Data Recovery Professional is the...

MASTER ROSHI NEEDS TO BE STOPPED! (Kame Paradise)

July 9, 2020

July 9, 2020 49

What kind of training is Master Roshi teaching Goku? And by the way, where’s Krillin in this timeline? Welcome to...

strike force heroes 2 hacked 2016 – (updated and working) God mode, unlimited weapons and golden gun

July 12, 2020

July 12, 2020 17

Get your strikes force heroes 2 hacked here : Other Keywords( ignore these ) strike force heroes 2 hacked air...

Diễn đàn CEO: CEO StoxPlus và mô hình kinh doanh dữ liệu và phân tích – Stox.vn

July 9, 2020

July 9, 2020 6

(STOX) — Vừa qua, ông Nguyễn Quang Thuân, Tổng Giám đốc Công ty Cổ phần Truyền thông Tài chính StoxPlus...

Character arrays and pointers – part 1

July 9, 2020

July 9, 2020 26

See complete series on pointers in C/C++ here: See part 2 of this lesson here: In this lesson, we have...

Perfect Outlook PST Recovery Software (Repairs all PST Files)

July 9, 2020

July 9, 2020 11

Outlook PST Recovery Software Get the Outlook PST Recovery Software here – Tried repairing corrupt or damaged Outlook PST file...

[Khóa học lập trình Python cơ bản] – Bài 7: Kiểu chuỗi trong Python – Phần 1 | HowKteam

July 9, 2020

July 9, 2020 32

[Khóa học lập trình Python cơ bản] – Bài 7: Kiểu chuỗi trong Python p1 | HowKteam Nếu các bạn...

Đặt hộ là gì? Đặt ảo là gì? Giải đáp thắc mắc về đặt hộ đơn Shopee Lazada Sendo

July 11, 2020

July 11, 2020 21

Xem Top Ứng Dụng kiếm tiền online uy tín miễn phí trên điện thoại Chào mừng các bạn đã đến...

DIY Planner Dashboard | Sticky Notes & Page Flags

July 13, 2020

July 13, 2020 22

Have you seen these videos? Plan with Me | Erin Condren | Bee & Honey Theme Plan with Me &...

StoxPlus Rebranded As FiinGroup

July 13, 2020

July 13, 2020

STOXPLUS REBRANDED AS FIINGROUP REFLECTING ITS GREATER VISION & GROWTH STRATEGY “StoxPlus had over a decade of expertise as a...

D-Edition TV präsentiert das Carson Stromracer FD Buggy Produktvideo 500404037

July 8, 2020

July 8, 2020 2

Mehr Informationen zu diesem Fahrzeug sind auf unserer Hompage erhältlich: FastDrive – Die Modellserie für Racing Fans! Der FD Stormracer...

[STRANDED DEEP #6] KHÔNG CHO MAP THÌ TỰ VẼ MAP

July 13, 2020

July 13, 2020 3

Góp tiền cho chuột mua game tại đây: Đừng quên để lại những ý kiến đóng góp cũng như những...

Static in C++

July 9, 2020

July 9, 2020 39

Twitter ► Instagram ► Patreon ► Slack ► Series Playlist ► Static in a class scope ► Coming soon… Check...

Using StringStream to extract integers from strings in C++ (HackerRank)

July 12, 2020

July 12, 2020 10

Solution for StringStream in C++, one of the most popular HackerRank problem solving questions. Learn how to use StringStream in...

Perfect SKX Mods Part 1.5 – Strapcode/Miltat Super Oyster!!

July 11, 2020

July 11, 2020 28

**BUY A STRAPCODE HERE FOR YOUR SKX!!!** *CHECK OUT MY TOP VALUE WATCHES AND ACCESSORIES ON AMAZON!* *USE THE CODE...

Comments
  • 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!

  • 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

  • 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.

  • 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

  • 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?

  • 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?

  • You no longer need to use #include <string> in order to print strings at least that's what happens to me while using CodeBlocks

  • 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?

  • You told that string in function arguments dynamically allocated to heap, but it is not. Function arguments is a auto memory (stack allocation).

  • I was able to use 'cout' to print the string to the console without including the string.h header file. But you said it will be an error. How come?

  • char* name ="Cherno"; //E0144 a value of type "const char *" cannot be used to initialize an entity of type "char * – VS 2019

  • Hi can anyone explain why we can declare char* example = "cherno" but not int* example = {1,2,3,4,5}

  • 6:08
    I wrote same code in my vs2019 but it's giving error stating
    "cannot convert from const char[7] to char *"

  • I tried your example
    char name2[6] = {'c','h','e','r','n','o'}

    and my output was fine, no strange ascii characters or anything. Maybe C++ has updated it since this video?

Leave a Reply

Your email address will not be published. Required fields are marked *