c语言中数字前追加0000

来源:互联网 发布:结婚证生成软件 编辑:程序博客网 时间:2024/06/09 23:54
//string转换为char *
const char *a;
string s = "192.168.1.1";
a = s.c_str();
//string转换为int
string ss;
int k = atoi(ss.c_str());

//字符串前追加000
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
        char buff[100];
    char buff1[100];
    int b = 6.78;
    sprintf(buff1,"%d",b);
    string ss = buff1;
    ss = "0000" + ss;
    sprintf(buff,"0000%s",ss.c_str());
}
0 0
原创粉丝点击