我们定义string A,进行g++编译得:输出为空!很奇怪
#include<iostream>
#include<string>
using namespace std;
int main()
{
string A="";
string str="1234";
int i,j,n=2;
for(i=0;i<n;i++)
{A[i]=str[i];}
A[i]='\0';
cout<<A<<endl;
}
我们定义string A,进行g++编译得:输出为空!很奇怪
#include<iostream>
#include<string>
using namespace std;
int main()
{
string A="";
string str="1234";
int i,j,n=2;
for(i=0;i<n;i++)
{A[i]=str[i];}
A[i]='\0';
cout<<A<<endl;
}
转载于:https://www.cnblogs.com/cxy931980808/p/6649085.html