string readString(string p)
{
string s;
cout << p;
cin >> s;
return s;
}
int main()
{
string oper = readString("? ");
while (oper != "Q")
{
if (oper == "l")
cout << "load complete" << endl;
else if (oper == "+")
cout << "add complete" << endl;
string oper = readString("? ");
}
}
Run Code Online (Sandbox Code Playgroud)
当我输入时l
,输出是load complete
.但后来我输入+
,它仍然输出load complete
.为什么不输出add complete
?
#include <string>
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
class matrix
{
public:
matrix(int);
void func(int);
vector<vector<double> > m;
};
matrix::matrix(int size)
{
//set 3 X 3 = 9 elements to zero
vector<vector<int> > m(size, vector<int>(size));
// success
cout << "test1 if m[0][0] equals to zero: " << m[0][0] << endl;
}
void matrix::func(int size)
{
// failure, can't pass till here
cout << "test2 if m[0][0] equals to zero: " << m[0][0] << endl;
for(int i = …
Run Code Online (Sandbox Code Playgroud)