字符数组,字符串、数字转化
生活随笔
收集整理的這篇文章主要介紹了
字符数组,字符串、数字转化
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
<p style="margin-top: 5px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; line-height: 26px; word-wrap: break-word; color: rgb(102, 102, 102); font-family: 宋體, Arial; font-size: 16px;">//***************************************************</p><p style="margin-top: 5px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; line-height: 26px; word-wrap: break-word; color: rgb(102, 102, 102); font-family: 宋體, Arial; font-size: 16px;">//更多精彩,歡迎進(jìn)入:http://shop115376623.taobao.com</p><p style="margin-top: 5px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; line-height: 26px; word-wrap: break-word; color: rgb(102, 102, 102); font-family: 宋體, Arial; font-size: 16px;">//***************************************************</p>
</pre><pre name="code" class="cpp">// String2Char2Data.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
int main()
{
字符數(shù)組換為字符串
// char a[10]="aaaabbbba";
// string s(&a[0],&a[strlen(a)]);//strlen:求字符串長(zhǎng)度,測(cè)量字符串長(zhǎng)度的函數(shù) s(字符數(shù)組a開(kāi)始的地址,字符數(shù)組a結(jié)束的地址)
// cout<<s<<endl;
// system("pause");// 把字符串轉(zhuǎn)換為字符數(shù)組
// string s="aaaavvva";
// char a[10];
// strncpy(a,s.c_str(),s.length());//strncpy:將字符串src中最多n個(gè)字符復(fù)制到字符數(shù)組dest中
// /*c_str()函數(shù)返回一個(gè)指向正規(guī)C字符串的指針, 內(nèi)容與本string串相同.
// 這是為了與c語(yǔ)言兼容,在c語(yǔ)言中沒(méi)有string類型,故必須通過(guò)string類對(duì)象的成員函數(shù)c_str()把string 對(duì)象轉(zhuǎn)換成c中的字符串樣式。*/
// for(int i=0;i<s.length();i++)
// {
// cout<<a[i]<<" ";
// }
// cout<<endl;
// system("pause");// 把字符數(shù)組轉(zhuǎn)換為數(shù)字
// //char a[2] = "a";
// char a[4] = "123";
// int x;
// x=atoi(a);
// // atoi函數(shù)原型:
// // int atoi(char *str)
// // 函數(shù)用途:
// // 將字符串轉(zhuǎn)換成一個(gè)整數(shù)值
// // 輸入?yún)?shù):
// // str 待轉(zhuǎn)換為整型數(shù)的字符串
// // 返回值:
// // 成功返回轉(zhuǎn)換后的數(shù)值,失敗則返回0.
// cout<<x+1<<endl;
// getchar();
// system("pause");
}
總結(jié)
以上是生活随笔為你收集整理的字符数组,字符串、数字转化的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 炉石传说游戏系统拆解和部分系统分析
- 下一篇: 微信小程序:宝宝起名神器