c++ - 如何通过用空格('')分隔文件路径来循环字符串并将其存储到C++中的向量/数组中
问题描述
我有一个具有多个文件路径的字符串,如下所示:
%programdata%\EMR\Registration\Registration_EMR.xml C:\ProgramData\EMR\Registration\RegistrationEMR.xml
%AppData%\EMR\EMR Setup\REGDATA\registration_EMR.xml %AppData%\EMR\EMR Setup\REGDATA\RegistrationEMR.xm
我想通过用空格('')分隔文件路径来循环字符串并将其存储到向量/数组中。
以便向量/数组包含以下用空格分隔的路径。
%programdata%\EMR\Registration\Registration_EMR.xml
C:\ProgramData\EMR\Registration\RegistrationEMR.xml
%AppData%\EMR\EMR Setup\REGDATA\registration_EMR.xml
%AppData%\EMR\EMR Setup\REGDATA\RegistrationEMR.xml
有人可以帮我吗?
更新代码:
我修改了 ReadJsonFile 函数,如下所示,在每个 .xml 之后拆分文件路径,然后调用 ExpandEnvironmentStrings,然后将每个文件路径存储到向量中。
我在标记字符串时遇到了困难,因为我们只能标记 char*。
我收到以下错误:
“const WCHAR *”类型的参数与“char *”类型的参数不兼容,重载函数“ExpandEnvironmentStringsW”的实例不匹配参数列表
bool EMRFileReader::ReadJsonFile(const std::wstring &strFilePath, std::wstring &strFileContent)
{
std::vector<std::wstring> pathsVector;
const WCHAR *wpszPathToSearch = strFilePath.c_str();
TCHAR szOut[MAX_PATH];
char *token = strtok(wpszPathToSearch, ".xml");
//argument of type "const WCHAR *" is incompatible with parameter of type "char *"
while (token != NULL)
{
ExpandEnvironmentStrings(token, szOut, ARRAYSIZE(szOut));
//no instance of overloaded function "ExpandEnvironmentStringsW" matches the argument list
pathsVector.push_back(szOut);
}
return true;
}
解决方案
推荐阅读
- flutter - 如何在 TimePicker Flutter 中永久保存 Picked Time
- sql - 选择另一列时 LISTAGG 不起作用
- android - 单例模式 - 应用程序被操作系统杀死(内存释放)后启动画面不启动 Android
- node.js - 开玩笑测试 - 请在入口点的顶部添加“import "reflect-metadata""
- c# - 多列上的 Blazor 过滤引导表
- kubernetes - Clickhouse 作为带有副本的 Kubernetes 部署
- typescript - 强制对象包含枚举的所有键,并且仍然对其值进行类型推断
- assembly - 如何在 ARM64 mov 指令中对寄存器进行编码?
- python - 在 rasperry PI 上通过 GPIO 上拉设置
- python - Pandas:如何用两个数据帧的高级索引替换循环?