不知道为什么这不起作用,一切似乎都是正确的,但也许我错过了一些明显的东西,因为我刚刚开始了解 C++。
程序:
#include <iostream>
#include <string>
using namespace std;
string ask(){
string ans2;
cout << "Type:";
cin >> ans2;
return ans2;
}
int main()
{
string ans2;
string ans1="Hello";
ask();
cout << ans1 << " turns into " << ans2;
return 0;
}
带有以下错误消息:
Line 20:[Error] no match for call to '(std::string {aka std::basic_string<char>}) (std::string&)'
Line 6:[Error] 'ans2' was not declared in this scope
Line 6:[Error] expected ',' or ';' before '{' token