C++ 无法识别函数调用
我正在为一项作业写一个魔法八球程序。我所有的函数调用都能工作,只有一个除外。我一直收到一个错误,说没有匹配的函数调用。打电话时使用了原型的副本,所以我知道这不是打字错误。我不明白为什么,因为我觉得它的设置是正确的 main.cpp:C++ 无法识别函数调用,c++,C++,我正在为一项作业写一个魔法八球程序。我所有的函数调用都能工作,只有一个除外。我一直收到一个错误,说没有匹配的函数调用。打电话时使用了原型的副本,所以我知道这不是打字错误。我不明白为什么,因为我觉得它的设置是正确的 main.cpp: int main() { const int MAXSIZE = 100; int size; string responses[MAXSIZE]; string categories[MAXSIZE]; srand(tim
int main() {
const int MAXSIZE = 100;
int size;
string responses[MAXSIZE];
string categories[MAXSIZE];
srand(time(0));
start:
cout << "A. Read responses/categories from file" << endl;
cout << "B. Play Magic Eight Ball" << endl;
cout << "C. Sort by responses" << endl;
cout << "D. Sort by categories" << endl;
cout << "E. Write responses/categories to a file" << endl;
cin >> input;
ifstream infile;
ofstream outfile;
switch (input) {
case ('A'):
case ('a'):
readResponses(infile, responses, categories , MAXSIZE, size);
break;
...
intmain(){
常数int MAXSIZE=100;
整数大小;
字符串响应[MAXSIZE];
字符串类别[MAXSIZE];
srand(时间(0));
开始:
cout在函数readResponses
中,您声明了string categories
,并使用string categories[]
在您的定义中我不断收到一个错误,说没有匹配的函数可调用。请编辑您的问题并添加错误消息的确切文本。如果这是Visual Studio,则从“输出”选项卡复制该错误,其格式比错误列表的格式更好。在主类别中
是一个数组,在readRespon中ses
类别
是一个字符串为什么要使用开始:
标签?在大多数(90%+)程序中,不需要标签。
#include <iostream>
#include <string>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
#ifndef UNTITLED_FUNCTIONS_H
#define UNTITLED_FUNCTIONS_H
void readResponses(ifstream &infile, string responses[], string categories ,const int MAXSIZE, int &size );
#endif //UNTITLED_FUNCTIONS_H
#include <iostream>
#include <string>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include "functions.h"
using namespace std;
void readResponses(ifstream &infile, string responses[], string
categories[], const int MAXSIZE, int &size ) {
string s;
int num = 0;
infile.open("magic.txt");
size = 0;
while (getline(infile,s) && (num < MAXSIZE)) {
responses[num] = s;
getline(infile, s);
categories[num] = s;
num++;
}
size = num;
infile.close();
}