b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

c++ strchr函数_strchr函数返回_模拟实现strchr函数(22)

电脑杂谈  发布时间:2017-02-28 08:29:56  来源:网络整理

dec 置基数为10 相当于"%d"

hex 置基数为16 相当于"%X"

oct 置基数为8 相当于"%o"

setfill( 'c' ) 设填充字符为c

setprecision( n ) 设显示有效数字为n位

setw( n ) 设域宽为n个字符

setbase(int n) : 将数字转换为 n 进制.

举例:

cout<<setbase(8)<<setw(5)<<255<<endl;

cout<<setbase(10)<<setw(5)<<255<<endl;

cout<<setbase(16)<<setw(5)<<255<<endl

输出结果:

(空)(空)377

(空)(空) 255

(空)(空)(空) f f

#include<iomanip>

cout<<setprecision(位数); //控制总位数

cout<<setiosflags(ios::fixed)<<setprecision(位数); //控制小数点后位数

#include <stdlib.h>

把字符串转换成整型数

#include<stdlib.h>

#include<stdio.h>

int main()

{

float n;

char const* str="12345.67";

n=atoi(str);

printf("string = %s integer = %f \n",str,n);

return 0;

}

输出结果:

string = 12345.67 integer = 12345.000000

#include<stdlib.h>

#include<stdio.h>

int main()

{

char a[]="-100";

char b[]="123";

int c;

c=atoi(a)atoi(b);

printf("c=%d\n",c);

return 0;

}

输出结果:

c=23

与atoi相同

与atoi相同

#include <stdlib.h>

功能:;

把整型数转换成字符串

#include<stdlib.h>

#include<stdio.h>

int main()

{

int number=123456;

char string[25];

itoa(number,string,10);

printf("integer = %d string = %s\n",number,string);

return 0;

}

输出结果:

integer = 123456string = 123456

把浮点数转换成字符串

#include<iostream>

#include<cstdlib>

using namespace std;

int main()

{

double number=123456.67;


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-34960-22.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...