13,825
社区成员
发帖
与我相关
我的任务
分享
#include <vcl.h>
#include <string>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
bool m_stop;
std::string f;
//string f;
f.append(0,2);
f[0]=1;
f[1]=3;
//f="cd";
//char f[2]={1,3};
//char f=2;
//string s;
std::string s;
s.append(0,5);
s[0]=1;
s[1]=2;
s[2]=1;
s[3]=3;
s[4]=1;
//s="abcde";
unsigned int pp=0;
pp=s.find(f);
m_stop=false;
}
std::string s;
s.append(0,5);
s[0]=1;
s[1]=2;
s[2]=0; // "\0’
s[3]=3;
s[4]=1;
s.size();
这个代码,s的大小是5
当然,如果你调用 s.c_str(),那么只会得到0之前的两个元素,因为c_str()方法,是以数字0,也就是'\0'来作为结尾的