我无法找到解决问题的方法,我认为它与重载函数有关,但我似乎无法弄清楚如何解决它.
这是我的function.cpp
#include "CountLetter.h"
int Countletter(string sentence, char letter) {
int size = sentence.length();
int toReturn = 0;
for (int i = 0; i<= size; ++i) {
if (sentence[i] == letter) {
toReturn++;
}
}
return toReturn;
}
Run Code Online (Sandbox Code Playgroud)
这是我的function.h
#ifndef FN_H
#define FN_H
#include <iostream>
using namespace std;
int CountLetter(string sentence, char letter);
#endif
Run Code Online (Sandbox Code Playgroud)
我的main.cpp
#include "CountLetter.h"
int main() {
string sent = "";
char let = ' ';
int times = 0;
cout << "Enter a sentence.\n";
getline(cin, sent); …Run Code Online (Sandbox Code Playgroud)