我有一個C++程序,它根據用戶輸入的內容打開一個url。C++程序中的未知錯誤
下面的代碼:
#include <iostream>
#include <string>
using namespace std;
int main(){
int i = 1;
string google = "https://www.google.com/search?q=";
string input;
getline(cin, input);
string changeSpace(string input)
{
for (int i = 0; i < text.length(); i++)
{
if (text[i] == ' ')
text[i] = '+';
}
return text;
}
input = changeSpace(input);
cout << input << endl;
string url = string(google + input);
system(string("start " + url).c_str());
cout << url << endl;
}
的錯誤是在這裏:
string changeSpace(string input)
{
在它說的支架,預計一個 「;」
而且我不知道爲什麼ocurrs那個錯誤,這可能是一個簡單的錯誤,但我不知道它。
請幫幫我。
函數定義不在函數中。 – jaggedSpire
你在'main'中使'changeSpace'成了一個內聯函數將它移到int main()' – AndyG
@jaggedSpire:嗯,它們可以和lambdas類似(儘管它們實際上只是函數對象:-)) – AndyG