String

String

std::string name = "Cherno";
name += "Hello";

void PrintString(const std::string& string)
{
std::cout << string << endl;
}

## 关于转义符'\0'

对于一个字符串,字符串结尾自带一个'\0'表示字符串结束,转义符占位
例如,下面的字符串大小是7而不是6.

char name[7] = "Cherno";
char name[8] = "Che\0no";
strlen(name);

因为识别到\0后停止,所以strlen()返回的值是三
#include<iostream>
#include<string>
#include<stdlib.h>

int main()
{
    using namespace std::string_view_literals;
    std::string name0 = "Cherno"s + "hello";
    
    const char* example = R"(Line 1 
    Line2
    Line3
    Line4)";//'R' represents Raw,which makes skip '\0'. 
// OR......
    const char* ex = "Line1\n"
        "Line2\n"
        "Line3\n";
    const char* name = u8"Cherno";
    const wchar_t* name2 = L"Cherno";
    const char16_t *name3 = u"Cherno";
    const char32_t *name4 = U"Cherno";

    std::cout << name << std::endl;
    std::cin.get();
}
posted @ 2025-09-21 10:18  EcSilvia  阅读(3)  评论(0)    收藏  举报