C++中string类型 任性!
来源:互联网 发布:高新区行知小学 重点 编辑:程序博客网 时间:2024/04/29 16:57
/* C++中的新成份——string类型 */#include<iostream>#include<cstring>using namespace std;int main(){ char str1[50],str2[50],temp[50]; cout <<"please input strings:"; cin>>str1>>str2; if(strcmp(str1,str2)>0) { strcpy(temp,str1); strcpy(str1,str2); strcpy(str2,temp); } cout<<"now,they are:"; cout<<str1<<","<<str2<<endl;}#include<iostream>#include<string>using namespace std;int main(){ string str1,str2,temp; cout<<"please input strngs:"; cin>>str1>>str2; if(str1>str2) { temp=str1; str1=str2; str2=temp; } cout<<"now,they are:"; cout<<str1<<","<<str2<<endl;}#include<iostream>#include<cstring>using namespace std;int main(){ char *str1,*str2,temp;//错误的! 野指针 cout<<"please input strings:"; cin>>str1>>str2; if(strcmp(str1,str2)) { strcpy(temp,*str1); strcpy(*str1,*str2); strcpy(*str2,temp); } cout<<"now,they are:"; cout<<str1<<","<<str2<<endl;}
阅读全文
0 0
- C++中string类型 任性!
- c/c++中string类型的构造
- c中没有string字符串类型
- C语言中没有String类型
- C++string类型详解
- C++ STL string类型
- c++string类型管理
- c#string类型探讨
- 关于JAVA中String类型内存关系分析c
- char类型和string类型(C++,C#)
- char类型和string类型(C++,C#)
- PHP中String类型
- javascript中String类型
- C++中有string类,string是一个类不是一种类型,c语言中没有
- C++/CLI 中字符串类型的转化: 把System::String转化为std::string
- C++/CLI 中字符串类型的转化: 把std::string转化为System::String
- 关于C#string的类型
- C string类型的用法
- redis限制单ip、单用户的访问次数
- React 组件不渲染的坑...
- 最新版本的 Xcode 8+ Alcatraz 插件安装?
- 电感的作用
- JAXB的@XmlAccessorType和@XmlTransient
- C++中string类型 任性!
- IMX6q的mipi-csi摄像头
- 30个php操作redis常用方法代码例子
- python 一些基本数据结构
- codeforces Educational Codeforces Round 21 A
- enum usage
- OpenCv 图像的放大和缩小
- 多视图几何之SVD
- 【php基础班】第10天 函数、return详解、函数调用、递归函数、数组