c++中char类型字符串拼接以及int类型转换为char类型 && 创建文件夹

如下所示:

#include <iostream>
#include <windows.h>
#include <cstring>
using namespace std;
int main() {
    char s1[10] = "wayne";
    char s2[10];
    int n = 10;

    itoa(n, s2, 10);
    strcat(s1,s2);
    
    cout << s1 << endl;
    system("pause");
    return 0;
}

引入cstring库的目的是为了使用strcat函数,另外,itoa函数接受三个参数,第一个参数是要转化的数字,第二个是转化为字符串后存放的位置,最后一个可以指定进制,如这里使用的是十进制。

而通过c++创建文件夹如下所示:

#include <iostream>
#include <windows.h>
#include <direct.h>
using namespace std;
int main() {
    _mkdir("current");
    system("pause");
    return 0;
}

即引入direct.h库文件,然后使用_mkdir()函数即可。

原文地址:https://www.cnblogs.com/zhuzhenwei918/p/8850363.html