C++中宏定义的字符串和string定义的字符串所占字节长度不同

#include <string>
#include <iostream>

using namespace std;

#define PI "圆周率"
#define j 100
int main(){
    string name = "圆周率";
    int i = 100;
    cout << name << '\n';
    cout << "PI所占字节长度:" << sizeof(PI) << endl;
    cout << "name所占的字节长度:" << sizeof(name) << endl;
    cout << "i所占的字节:" << sizeof(i) << endl;
    cout << "j所占的字节:" << sizeof(j) << endl;
    return 0;
}

输出结果
圆周率
PI所占字节长度:10
name所占的字节长度:24
i所占的字节:4
j所占的字节:4

这个问题暂时先放着。。

posted @ 2022-09-15 21:07  何侠客  阅读(195)  评论(0编辑  收藏  举报