' int main(int,int,std :: __ cxx11 :: string,std :: __ cxx11 :: string)'只接受零或两个参数[-Wmain]

时间:2018-03-02 00:06:46

标签: c++

c ++代码

#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;
}

我在互联网上搜索了错误,但我不明白答案 我是在日食和警告中写的!

'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]

我的错?

1 个答案:

答案 0 :(得分:2)

您不能以这种方式将参数传递给C ++程序。 main的签名应为

int main()

或者

int main(int argc, char* argv[])

在第二种情况下,您可以通过访问argv数组来检索传递给程序的参数,例如:

for(int i = 0; i < argc; ++i)
    cout << argv[i] << '\n';

请参阅有关如何解析参数的一些文档:

How to parse command line parameters.