我想编写可以帮助我提供包含给定文件夹的驱动器号的 C++ 代码。我正在编写给定的代码并在第 11 行将字符变量添加到字符串变量时出现错误。 谁能帮我纠正下面的代码。
#include "stdafx.h"
#include <string>
#include <windows.h>
#include <iostream>
#include "Shlwapi.h"
int main()
{
char var;
for (var = 'A'; var <= 'Z'; ++var)
{
char buffer_1[] = var +":\\PerfLogs"; ------->>>> line where i am getting the error
char *lpStr1;
lpStr1 = buffer_1;
int retval;
retval = PathFileExists(lpStr1);
if (retval == 1)
{
std :: cout << "Search for the file path of : " << lpStr1;
system("PAUSE");
}
}
}
最佳答案
你应该使用字符串库:
std::string str1="Str 1";
std::string str2=" Str 2";
str1.append(str2); //str1 = "Str 1 Str 2"
关于c++ - 如何在C++中将字符变量添加到字符数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50908833/