[英]c++ error: no matching function for call to ‘std::__cxx11::basic_string<char>::append<int>(int, int)’
[英]'int main(int, int, std::__cxx11::string, std::__cxx11::string)' takes only zero or two arguments [-Wmain]
代碼
#include <iostream>
#include <string>
using namespace std;
void hosgeldiniz (string a , string b)
{
cout << "Programa hosgeldiniz !!!\nSayin : " << a << " " << b ;
}
int main (int sayiB , int sayii , string ad , string soyad )
{
cout << "Adinizi giriniz\n";
cin >> ad;
cout << "Soyadinizi giriniz\n";
cin >> soyad;
hosgeldiniz (ad , soyad);
cin >> sayii;
}
我在互聯網上搜索了錯誤,但我不明白我在 eclipse 和警告中寫的答案!
'int main(int, int, std::__cxx11::string, std::__cxx11::string)' takes only zero or two arguments [-Wmain]
second argument of 'int main(int, int, std::__cxx11::string, std::__cxx11::string)' should be 'char **' [-Wmain]
third argument of 'int main(int, int, std::__cxx11::string, std::__cxx11::string)' should probably be 'char **' [-Wmain]
我的錯在哪里?
您不能以這種方式將參數傳遞給 C++ 程序。 main
的簽名應該是
int main()
或者
int main(int argc, char* argv[])
在第二種情況下,您可以通過訪問argv
數組來檢索傳遞給程序的參數,例如:
for(int i = 0; i < argc; ++i)
cout << argv[i] << '\n';
請參閱有關如何解析參數的一些文檔:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.