功能
上色
#include<windows.h>
void color(int ForgC, int BackC) //0~15
{
/*
0=黑色,1=蓝色,2=绿色,3=湖蓝色,4=红色,5=紫色;
6=黄色,7=白色,8=灰色,9=淡蓝色,10=淡绿色,11=浅绿色;
12=淡红色,13=淡紫色,14=淡黄色,15=亮白色。
*/
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
//eg:
int main()
{
color(14,0);
cout<<"hello"<<endl;
return 0;
}
获取文件目录
#include <direct.h>
#include <stdio.h>
char buffer[MAX_PATH];
getcwd(buffer, MAX_PATH);
文件夹
创建
#include <Windows.h> //头文件
#include<iostream>
using namespace std;
int main()
{
string path = "E:\\1";
bool flag = CreateDirectory(path.c_str(), NULL);
return 0;
}
删除
#include <iostream>
#include <Windows.h> //头文件
using namespace std;
int main()
{
string path = "E:\\1";
bool flag = RemoveDirectory(path.c_str());
return 0;
}
检查是否存在
#include<direct.h>
#include<io.h>
#include<iostream>
using namespace std;
int main()
{
string path = "D:\\test1";
if (access(path.c_str(), 0) == -1)//返回值为-1,表示不存在
{
printf("不存在,创建一个\n");
int i = mkdir(path.c_str());
}
return 0;
}
/*
amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1。
这个函数还可以检查其它文件属性:
06 检查读写权限
04 检查读权限
02 检查写权限
01 检查执行权限
00 检查文件的存在性
而这个就算这个文件没有读权限,也可以判断这个文件存在于否
存在返回0,不存在返回-1
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/cao_jie_xin/article/details/114302984
*/
easyX
initgraph(ROW*SPACE,COL*SPACE);
RECT r;
r.left = r.top = 0;
r.right = r.bottom = SPACE;
settextstyle(20, 0, _T("宋体")); // 设置文本的字体大小为20,字体为宋体
while (1)
{
drawtext(LPCTSTR("hello"),&r, DT_CENTER);
}
int double 格式化转为字符串
- 代码
#include <iostream>
#include <sstream>
int main() {
int num = 42;
float f = 3.14;
std::stringstream ss;
ss << "The number is " << num << " and the float is " << std::fixed << std::setprecision(2) << f;
std::string formattedString = ss.str();
std::cout << "Formatted string: " << formattedString << std::endl;
return 0;
}
- 结果:
Formatted string: The number is 42 and the float is 3.14