My issue is that I keep getting the "expected primary-expression before ')' token" error on the variable "string" in the while loop in the NumWords function. The variable works fine in the "istringstream inSS(string);" line but when I try to compile the code the next line produces that error. Please help I am so confused and it is driving me crazy.
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
//Function prototypes
int NumWords(const string&);
int NumNonWSCharacters(const string&);
void CharReplace(string&, char, char);
char PrintMenu();
//Main function
int main () {
//Variables
string text;
//Input & Output original
cout << "Enter a line of text: ";
getline(cin, text);
cout << "\n";
cout << "You entered: " << text << "\n";
//How many words
cout << NumWords(text);
}
//Counts the number of words in a string
int NumWords(const string&) {
int count = 0;
istringstream inSS(string);
while (inSS >> string) {
count++;
}
}
//Count the number of characters (not including whitespace) in a string
int NumNonWSCharacters(const string&) {
cout << "FINISH\n";
}
//Replaces one character with another in a given string
void CharReplace(string&, char, char) {
cout << "FINISH\n";
}
//Prints the menu
char PrintMenu() {
cout << "FINISH\n";
}
Aucun commentaire:
Enregistrer un commentaire