c++ - 如何在C++中将字符变量添加到字符数组

标签 c++

我想编写可以帮助我提供包含给定文件夹的驱动器号的 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/

相关文章:

c++ - C++中用户定义的行、列输出

c++ - 由于加号或减号,if/else 语句输出未显示正确的消息

c++ - 从库中查找 argc 和 argv

c++ - 我的 win32 程序应该在哪里保存它的文件?

c++ - 提取 C++ 模板参数

c++ - cpp WinAPI WndProc 包装在类中

c++ - 每次循环运行时如何更改for循环中的对象

c++ - 重载输出运算符给出十六进制数而不是字符串

c++ - 具有两个不同 View 的 Qt 数据模型

c++ - AMP C++ 加速体积计算