12.23.cpp : 定义控制台应用程序的入口点。
2016-03-03 15:34
381 查看
// 12.23.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <memory>
#include<string>
using namespace std;
#pragma warning( disable : 4996) //关闭 strcpy不安全错误。
/*int main()
{
char a[] = "C++";
char b[] = "Primer";
size_t i = sizeof(a)+sizeof(b);
char *cp = new char[i];
strcpy(cp, a);
strcat(cp, b);
cout << cp << endl;
delete[] cp;
return 0;
}*/
int main()
{
string a = "c++";
string b = "primer";
size_t i = a.size() + b.size();
string *cp = new string[i];
a = a + b;
cout << i << " " << a << endl;
for (int j = 0; j != i; j++)
{
cp[j] = cp[j] + a[j];
cout << cp[j] << " ";
}
delete[] cp;
return 0;
}
//
#include "stdafx.h"
#include <iostream>
#include <memory>
#include<string>
using namespace std;
#pragma warning( disable : 4996) //关闭 strcpy不安全错误。
/*int main()
{
char a[] = "C++";
char b[] = "Primer";
size_t i = sizeof(a)+sizeof(b);
char *cp = new char[i];
strcpy(cp, a);
strcat(cp, b);
cout << cp << endl;
delete[] cp;
return 0;
}*/
int main()
{
string a = "c++";
string b = "primer";
size_t i = a.size() + b.size();
string *cp = new string[i];
a = a + b;
cout << i << " " << a << endl;
for (int j = 0; j != i; j++)
{
cp[j] = cp[j] + a[j];
cout << cp[j] << " ";
}
delete[] cp;
return 0;
}
相关文章推荐
- C++学习笔记(1)<unfinshed>
- C++设计模式之工厂方法模式
- 谈谈C++中各种初始化方式
- [C语言] C 语言学习代码
- htonl() htons()及inet_ntoa() inet_addr()的用法
- C++语言-08-命名空间
- C++11,正则表达式应用
- C语言字符判断、大小写互转(五)
- ‘之’字形打印矩阵
- leetcode - Count of Smaller Numbers After Self
- TypeError: No to_python (by-value) converter found for C++ type:
- 浅析C++中的this指针
- C++获得主机IP地址
- C++ 运算符优先级
- c++重载、覆盖、隐藏的区别和执行方式
- 《编写高质量代码:改善C++程序的150个建议》读书笔记4
- 1089. Insert or Merge (25)
- 【转】C/C++基本编程技能
- C/C++编程技能【整理】
- C语言之volatile【整理】