"错误:在'.标记'之前出现预期的主表达式,我不知道为什么

"error: expected primary-expression before '.' token" shows up and I don't know why

本文关键字:表达式 为什么 我不知道 错误 quot 标记      更新时间:2023-10-16

我对C++很陌生,我不确定为什么"字符串c = print.say(z(;"会产生错误,如果我把它放在main或while循环中。

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class print {
public:
int x;
string say(int x) {
switch (x) {
case 1: return "text1";
case 2: return "text2";
case 3: return "text3";
default: return "default";} } };
int main() {
int y = 1;
int z = 1;
while (y == 1) {
cin >> z;
string c = print.say(z);
cout << c; } }

没关系,我只需要这样做:

int main() {
print print;
int y = 1;
int z = 1;
while (y == 1) {
cin >> z;
string c = print.say(z);
cout << c; } }
相关文章: