将字符串str1复制为字符串str2的三种方法
1.自己编写函数,将两个字符串进行复制
#include<iostream>
using namespace std;
int main(){
char str1[]="I love China!",str2[20];
void Strcpy(char *p1,char *p2);
Strcpy(str2,str1);
cout<<"str1: "<<str1<<endl;
cout<<"str2: "<<str2<<endl;
return 0;
}
void Strcpy(char *p2,char *p1){
int i=0;
for(;*p1!='\0';p1++,p2++){
*p2=*p1;
}
*p2='\0';
}
2.使用函数库重的strcpy函数
#include<iostream>
using namespace std;
int main(){
char str1[]="I love China!",str2[20];
strcpy(str2,str1);
cout<<"str1: "<<str1<<endl;
cout<<"str2: "<<str2<<endl;
return 0;
}
3.定义两个字符串变量,然后直接进行赋值
#include<iostream>
#include<string>
using namespace std;
int main(){
string str1="I love China!",str2;
str2=str1;
cout<<"str1: "<<str1<<endl;
cout<<"str2: "<<str2<<endl;
return 0;
}
将字符串str1复制为字符串str2的三种方法的更多相关文章
- js字符串转换为数字的三种方法。(转换函数)(强制类型转换)(利用js变量弱类型转换)
js字符串转换为数字的三种方法.(转换函数)(强制类型转换)(利用js变量弱类型转换) 一.总结 js字符串转换为数字的三种方法(parseInt("1234blue"))(Num ...
- python字符串连接的三种方法及其效率、适用场景详解
python字符串连接的方法,一般有以下三种:方法1:直接通过加号(+)操作符连接website=& 39;python& 39;+& 39;tab& 39;+& ...
- JavaScript进阶(四)js字符串转换成数字的三种方法
js字符串转换成数字的三种方法 在js读取文本框或者其它表单数据的时候获得的值是字符串类型的,例如两个文本框a和b,如果获得a的value值为11,b的value值为9 ,那么a.value要小于b. ...
- ibatis SQLmap mysql模糊查询字符串拼的三种方法
在通常情况下iBATIS的参数在sqlmap中使用#param#的形式,参数名以’#’包着,但当使用sql的LIKE语句时就发生了问题,在单引号中无法使用#param#这种形式,下面列举出了3种方法来 ...
- [Python]实现字符串倒序的三种方法
a=" 1: print(a[::-1]) 2: b=list(a) b.reverse() print(''.join(b)) 3: c=len(a)-1 str_1=[] while(c ...
- python—字符串拼接三种方法
python—字符串拼接三种方法 1.使用加号(+)号进行拼接 字符串拼接直接进行相加就可以,比较容易理解,但是一定要记得,变量直接相加,不是变量就要用引号引起来,不然会出错,另外数字是要转换为字 ...
- 011-JSON、JSONObject、JSONArray使用、JSON数组形式字符串转换为List<Map<String,String>>的8种方法
一.JSON数据格式 1.1.常用JSON数据格式 1.对象方式:JSONObject的数据是用 { } 来表示的, 例如: { "id" : "123", & ...
- 007——转载——C#将字符串转换为整型的三种方法的总结
(一)转载——C#将字符串转换为整型的三种方法的总结 在C#中,要将一个字符串或浮点数转换为整数,基本上有三种方法: (1)使用强制类型转换:(int)浮点数 (2)使用Convert.ToInt32 ...
- {转}Java 字符串分割三种方法
http://www.chenwg.com/java/java-%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%88%86%E5%89%B2%E4%B8%89%E7%A7%8D%E6%9 ...
随机推荐
- android将drawable下的图片转换成bitmap
将drawable下的图片转换成bitmap 1. Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.xx ...
- GridView的简单使用
测试代码: activity_main.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/a ...
- Spring_总结_03_装配Bean(一)_自动装配
一.前言 本文承接上一节:Spring_总结_02_依赖注入 在上一节我们了解到依赖注入的实质就是装配. 这一节我们来学习下装配Bean的相关知识. 二.Bean的装配机制 1.三种装配机制 Spri ...
- python编程实例-使用正则收集IP信息
#!/usr/bin/env python from subprocess import PIPE,Popen import re def getIfconfig(): p = Popen(['ifc ...
- winform常用方法
1.对象的初始化器: Class a = new Class() { id = , name = "张三" } 2.窗体间传值 ①构造函数 ②单例函数 //单例模式:确 ...
- git教程3-添加远程库与从远程库拷贝
一.添加到github 1.github上创建新的库learngit.git 2.git remote add origin git@github.com:moisiet/learngit.git ...
- CodeForces - 900D: Unusual Sequences (容斥&莫比乌斯&组合数学)
Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such ...
- python模型字段
http://python.usyiyi.cn/translate/django_182/ref/models/fields.html#model-field-types
- 7.Selenium+Python实现搜索百度的测试用例
1.导入测试用例需要的模块,unittest是python的内置模块,它提供了组织测试用例的框架 import unittest # 导入测试用例的模块 2.测试用例继承于unittest class ...
- Linux测试程序 - 多线程
#include <sched.h> #include <pthread.h> main(){ pthread_t id0, id1, id2; ret=pthread_cre ...