在 C++ 控制台中输入含有中文和空格的路径,可以使用以下方法:

  1. 使用 std::getline() 函数读取一整行输入,包括空格和中文字符。例如:
#include <iostream>
#include <string>

int main()
{
    std::string path;
    std::getline(std::cin, path);
    std::cout << "Path: " << path << std::endl;
    return 0;
}
  1. 使用 std::wcin 和 std::wstring 读取 Unicode 字符串。例如:
#include <iostream>
#include <string>

int wmain()
{
    std::wstring path;
    std::wcin >> path;
    std::wcout << "Path: " << path << std::endl;
    return 0;
}

注意:上述方法在 Windows 系统中可行,但在 Linux 或 macOS 等系统中可能需要使用其他方法

c++控制台输入含有中文和空格的路径

原文地址: https://www.cveoy.top/t/topic/gB4v 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录