我对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; } }
答案 0 :(得分:0)
没关系,我只需要这样做:
int main() {
print print;
int y = 1;
int z = 1;
while (y == 1) {
cin >> z;
string c = print.say(z);
cout << c; } }