C++ C++;在int main中使用参数调用函数
如何在int main函数中调用void菜单函数? 我尝试了不同的参数,但我不知道如何调用菜单函数C++ C++;在int main中使用参数调用函数,c++,C++,如何在int main函数中调用void菜单函数? 我尝试了不同的参数,但我不知道如何调用菜单函数 //Compiling Error WordData.cpp: In function 'int main()': WordData.cpp:25:6: error: too few arguments to function 'void menu(std::string, int)' 25 | menu(); | ^ WordData.cpp:20:6: note
//Compiling Error
WordData.cpp: In function 'int main()':
WordData.cpp:25:6: error: too few arguments to function 'void menu(std::string, int)'
25 | menu();
| ^
WordData.cpp:20:6: note: declared here
20 | void menu(string,int);
更新它,因为需要我张贴完整的编码,以更好地理解我的问题,但我只想一种方法来调用菜单功能
//Compiling Error
WordData.cpp: In function 'int main()':
WordData.cpp:25:6: error: too few arguments to function 'void menu(std::string, int)'
25 | menu();
| ^
WordData.cpp:20:6: note: declared here
20 | void menu(string,int);
#包括
#包括
#包括
#包括
#包括“WordData.h”
#包括
使用名称空间std;
//WordData.cpp
//原型
无效菜单(字符串,int);
int main(){
//这个问题
菜单();
//............
返回0;
}
无效菜单(字符串wrd,int cnt)
{
WordData wd=WordData(wrd,cnt);
int选择;
bool-quit=false;
做
{
不能包含
无效菜单(字符串,int);
int main()
{
//这个问题
菜单(“你好”,1);
//............
返回0;
}
无效菜单(字符串wrd,int cnt)
{
std::cout必须通过函数传递参数。请尝试以下代码:
#include <iostream>
using namespace std;
void menu(string,int);
int main() {
menu("string",13);
}
void menu(string wrd,int cnt)
{
cout<< wrd << "\t" << cnt <<endl;
}
#包括
使用名称空间std;
无效菜单(字符串,int);
int main(){
菜单(“字符串”,13);
}
无效菜单(字符串wrd,int cnt)
{
cout在定义无效菜单(字符串wrd,int cnt)
时,必须调用菜单()
函数,并从main函数传递两个参数,如菜单(“code”,10)
。
您可以在菜单()中传递任何有效的字符串
和int
,您的问题中没有足够的信息,我们无法用特定代码回答。菜单()的定义清楚地说它需要两个参数。你需要传递这两个参数的有意义的值。如果你不知道如何做,那么你应该阅读C++教程或者看YouTube视频,教你如何。看起来你在尝试学习C++。不要这样做,读一本C++书。增加编译错误和编码。例如,有两个文件,WordData.cpp和WordData.h,您不了解错误消息的哪些部分?调用菜单时提供的参数数(零)小于该数(二)调用菜单
所需的参数。如何解决此问题?添加更多代码以帮助解释我的问题添加更多代码以帮助解释我的问题谢谢,这是一个简单但解释清楚的解决方案。救生员。
#include<string>
void menu(string,int);
int main()
{
//This problem here
menu("hello",1);
//............
return 0;
}
void menu(string wrd,int cnt)
{
std::cout << wrd << " " << cnt;
}
#include <iostream>
using namespace std;
void menu(string,int);
int main() {
menu("string",13);
}
void menu(string wrd,int cnt)
{
cout<< wrd << "\t" << cnt <<endl;
}