数组与string

#include <iostream.h>
#include <string.h>
using namespace std;

int main(){
int Arr[5];

// for(int i = 0; i < 5; i++){
// cout <<"the Arr :["<< i <<"]"<<endl;
// cin >> Arr[i]; //存入到数组里面
// }
//
// for(int i=0; i<5; i++){
// cout <<i<<":"<<Arr[i]<<endl;
// }


// int Arr2[5] = {2,3};
// for(int i=0;i<5;i++){
// cout <<i<<":"<<Arr2[i]<<endl;
// }
// char greeting[] = "hello world"; // 有12个字节 \0


// char buffer[80] = {'\0'};
// cout << "enter the string";
// cin >>buffer;
// cout << "here is the buffer:"<<endl<< buffer << endl;
//存在问题: 若多与79个字符则超出缓冲区,若输入空格则停止向缓冲区存储。
//cin.get()方法,待填充的缓冲区 读取的最大字符数 终止的限定符(默认为换行符)

// char buffer[80] = {'\0'};
// cout << "enter the string"<< endl;
// cin.get(buffer,79);
// cout << "here is the buffer:"<<endl<< buffer << endl;


// 函数strcpy() strncpy() 在string.h文件中 必须包含
// char String1[] = "no man is an island";
// char String2[80] = "\0";
// strcpy(String2,String1);
// cout << "String1:"<<String1<<endl;
// cout << "String2:" <<String2<<endl;

// const int MaxLength = 80;
// char String1[] = "no man is an island";
// char String2[MaxLength+1] = "\0";
// strncpy(String2,String1,MaxLength);
// cout << "String1:"<<String1<<endl;
// cout << "String2:" <<String2<<endl;


string str1 = "hello string";
cout << "str1:"<<str1<<endl;
string str2;
str2 = str1;
cout << "str2:"<<str2<<endl;
str2 = "this is c++ string";
cout << "str2:"<<str2<<endl;
string str3 = str1+str2;
cout << "str3:"<<str3<<endl;
//string 类子幕后为程序员管理内存和复制数据

// unsigned short someArr[5][4];
// for(int i=0; i<5; i++){
// for(int j=0; j<4; j++){
// someArr[i][j] = 0;
// }
// }

return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值