如何将完整字符串传递给批处理

How do I pass a full string to batch?

本文关键字:批处理 字符串      更新时间:2023-10-16

我正在编写一个C++程序,它可以让我搜索维基百科、谷歌、Wolfram Alpha等。我通过询问输入(我想用什么搜索,比如"猫的照片")来完成这项工作,然后我将输入传递给批处理,它在批处理中运行一个命令,用我的输入打开谷歌搜索。以下是它的样子:

string input;
cout<<"What do you want to search?"<<endl;
getline(cin, input, 'n');
system(("START https://www.google.com/search?q="+input).c_str());

问题是,如果我让它搜索"有趣的猫",它只搜索"有趣"。我该怎么办?除了使用cmd之外,我还愿意接受其他方法的建议。

Url对搜索字符串进行编码:https://en.wikipedia.org/wiki/Percent-encoding