当前位置: 代码迷 >> 综合 >> string,char,char*,char a[] 占字节数, 以及sizeof,strlen(),str.length()的用法
  详细解决方案

string,char,char*,char a[] 占字节数, 以及sizeof,strlen(),str.length()的用法

热度:68   发布时间:2024-01-19 15:41:05.0

 

// studystring.cpp : 
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
cout<<"char,char*,string 在C++中的占几个字节: -------------------------"<<endl;
cout<<"sizeof(char) = "<<sizeof(char)<<endl; //=1
cout<<"sizeof(char*) = "<<sizeof(char*)<<endl; //=4
cout<<"sizeof(string) = "<<sizeof(string)<<endl; //=16
cout<<"----------------------------------------------------------------"<<endl;
cout<<endl;cout<<endl;
string str;
str = "12345678912"; // 11个字符
cout<<"the size of str = "<<sizeof(str)<<endl; // = 16
cout<<"the length of str = "<<str.length()<<endl;// = 11 
cout<<"---------
  相关解决方案