文章目录
在应用程序编程中,有时需要选择桌面文件夹的路径,这时可以通过win32提供的api来获取,源代码如下所示:
1.获取桌面
- 1.获取桌面
- 2.jsoncpp
#include
#include
#pragma comment(lib, "shell32.lib")
std::string GetDesktopFolder()
{
char path[255];
SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, 0);
std::string rlt=path;
return rlt;
}
2.jsoncpp
在C++编码中,需要根据参数进行数据处理时,经常遇到的一个问题就是需要将关键的内存类属性数据转为文件保存,方便下次加载使用。使用jsoncpp开源库,下文展示一个范例代码,源代码如下所示:
#include
#include
#include
#include
#include
//加载文档
void ACustomDocumentInfo::LoadDocumentParaInfo(std::string filename)
{
// 打开文件
std::ifstream ifs(filename, std::ios::binary);
if (!ifs.good())
{
return;
}
//读取信息
Json::Value root;
Json::Reader reader;
if (!reader.parse(ifs, root)) {
return;
}
//转换信息
int sz = root.size();
for (int i = 0; i SetContentByJson(property.toStyledString());
m_ANormalLabelSizeMap[layer_name]=pANormalLabelSize;
}
}
}
void ACustomDocumentInfo::SaveDocumentParaInfo(std::string filename)
{
//打开文件
std::ofstream ofs(filename, std::ios::binary | std::ios_base::out | std::ios_base::trunc);
if (!ofs.good())
{
return;
}
//将map信息转为json
Json::Value root;
std::map::iterator it=m_ANormalLabelSizeMap.begin();
for (;it!=m_ANormalLabelSizeMap.end();it++)
{
//保存图层名
Json::Value jObject;
jObject["layer_name"]=it->first;
std::string json_str=it->second->GetContentByJson();
//常规尺寸标注
jObject["layer_type"]="normal_label_size";
//保存正常尺寸数据
Json::Reader reader;
Json::Value value;
if (reader.parse(json_str, value))
{
jObject["obj_property"]=value;
}
root.append(jObject);
}
ofssecond;
}
return jObject.toStyledString();
}
static std::string itoa_self(int i)
{
std::stringstream ss;
ss
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?