C ++-''之前的预期主表达式 [英] C++ -- expected primary-expression before ' '
本文介绍了C ++-''之前的预期主表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不熟悉C ++和编程,遇到了一个我无法弄清的错误.当我尝试运行该程序时,出现以下错误消息:
I am new to C++ and programming, and have run into an error that I cannot figure out. When I try to run the program, I get the following error message:
stringPerm.cpp: In function ‘int main()’:
stringPerm.cpp:12: error: expected primary-expression before ‘word’
在将变量分配给函数之前,我还尝试过在单独的行上定义变量,但最终还是得到相同的错误消息.
I've also tried defining the variables on a separate line before assigning them to the functions, but I end up getting the same error message.
有人可以提供一些建议吗?预先感谢!
Can anyone offer some advice about this? Thanks in advance!
请参见下面的代码:
#include <iostream>
#include <string>
using namespace std;
string userInput();
int wordLengthFunction(string word);
int permutation(int wordLength);
int main()
{
string word = userInput();
int wordLength = wordLengthFunction(string word);
cout << word << " has " << permutation(wordLength) << " permutations." << endl;
return 0;
}
string userInput()
{
string word;
cout << "Please enter a word: ";
cin >> word;
return word;
}
int wordLengthFunction(string word)
{
int wordLength;
wordLength = word.length();
return wordLength;
}
int permutation(int wordLength)
{
if (wordLength == 1)
{
return wordLength;
}
else
{
return wordLength * permutation(wordLength - 1);
}
}
推荐答案
调用 wordLengthFunction()
时不需要字符串".
You don't need "string" in your call to wordLengthFunction()
.
int wordLength = wordLengthFunction(字符串词);
应该是
int wordLength = wordLengthFunction(word);
这篇关于C ++-''之前的预期主表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文