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

Stick War Legacy | Mod Giant VIP Dame 999999999 | Stick War Legacy Hack | KasubukTQ

July 8, 2020

July 8, 2020 40

Stick War Legacy | #4 | Sẽ Thế Nào Khi Triệu Hồi 1 Tỷ StickGiant Cùng Lúc… | KadubukTQ ⬇️Cách...

SIÊU Tóm Tắt Season 5 | Steven Universe

July 10, 2020

July 10, 2020 24

SIÊU Tóm Tắt Season 5 | Steven Universe Script: Vũ Thuần Voice: Huy Anh Video: Sơn Nguyễn ► Subscribe: ►...

XÓM TRỌ 3D – PHIM CHIẾU RẠP | VIỆT HƯƠNG, HỒNG VÂN, MINH NHÍ, HUY KHÁNH, MAYA, TUẤN DŨNG, XUÂN NGHỊ

July 9, 2020

July 9, 2020 50

ĐĂNG KÝ KÊNH ĐỂ CÙNG ĐÓN XEM PHIM CHIẾU RẠP MỚI NHẤT: PHIM CHIẾU RẠP – XÓM TRỌ 3D FULL...

Multiple Stroke Layer Effect | Photoshop Tutorial

July 8, 2020

July 8, 2020 42

In this Photoshop tutorial, learn how to add multiple strokes to layer styles in order to create cool outline effects....

Draw Hyperrealistic Strawberry | Step-by-step Tutorial

July 8, 2020

July 8, 2020 35

GOOD NEWS… I just published my first BEGINNER to ADVANCED Sketching Course on Udemy. It’s currently on sale (for flat...

STATE OF DECAY 2 #1: SINH TỒN GIỮA NƯỚC MỸ NGÀY TẬN THẾ !!!

July 8, 2020

July 8, 2020 43

++ DONATE ĐỂ TTG MUA ĐƯỢC NHIỀU GAME HƠN TẠI: – – ++ MUA/THUÊ GAME BẢN QUYỀN GIÁ RẺ TẠI:...

How to Download and Install State of Decay 2 – CODEX PC

July 9, 2020

July 9, 2020 45

How to Download & Install State of Decay 2 – CODEX 1] Download State of Decay 2-CODEX : www.skidrow-games.com/ FitGirl...

STATIC VARIABLE OR STATIC DATA MEMBER IN C++ -24

July 12, 2020

July 12, 2020 46

STATIC VARIABLE OR STATIC DATA MEMBER In this video we will learn the Static Keyword in C++. We will learn...

How to download and install Stronghold 3 for free

July 8, 2020

July 8, 2020 26

Hey everyone! Today i am going to show you, How to download and install Stronghold 3 for free, but before...

25 Đồ Vật Mọi Người Thường Vứt Đi Nhưng Lại Rất Đáng Tiền

July 9, 2020

July 9, 2020

Làm sao để dùng lại đồ cũ. Bạn tính vứt cái khay làm đá cũ ấy vào thùng rác sao?...

[Khóa học lập trình Java nâng cao]Đọc ghi file FileInputStream, FileOutputStream, ObjectInputStream

July 11, 2020

July 11, 2020 5

Nội dung: Khóa học lập trình Java nâng cao Website học: Java là ngôn ngữ lập trình máy tính có...

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

Dòng Máu Ma Cà Rồng Phần 1 Nhạc Trẻ Remix

July 9, 2020

July 9, 2020 48

CHÀO MỪNG BẠN ĐẾN VỚ anime kenh các bạn giúp đạt được 1k sub nhe CONTACT US: • Email: haanh817@gmail.com...

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

Hướng dẫn tải và cài đặt game State of Decay 2

July 7, 2020

July 7, 2020 24

Hướng dẫn tải và cài đặt game State of Decay 2 – Link tải game: – Thể loại game: Game...

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 *