C++ 输入整数时如何中断for循环? #包括 #包括 使用名称空间std; int i; INTE; INTP; 字符名[10]={}; 不能像这样做吗- #include <iostream> #include <stdlib.h> using namespace std; int i; int e; int p; char name[10] = {}; cout<<endl<<"Please enter the letters of your name separated by enter, when you are done, type 'quit' "<<endl; for (e=0; e <= 10; e++) { cin>>name[e]; if (name[e] == 'quit') { break; } } for (p=0; p < ; p++) { cout<<name[p]; } return 0; } #包括 #包括 #包括 使用名称空间std; int i; INTE; INTP; 载体名称; 不能用a来表示。另外,使用std::string收集数据和检查输入的大小也会更容易。“quit”是一个字符串,它包含4个字符。不能将其视为单个字符。因此,必须使用双引号“”而不是单引号“”。 此外,此字符串保存在字符数组中,而不是单个字符变量中。所以 #include <iostream> #include <stdlib.h> #include <vector> using namespace std; int i; int e; int p; vector<string> name; cout<<endl<<"Please enter the letters of your name separated by enter, when you are done, type 'quit' "<<endl; while(1) { string tmp; cin>>tmp; if (tmp == "quit") { break; } else if(tmp.size()>10) { cout<<"Enter name with less then 11 character"<<endl; } else { name.push_back(tmp); } } for (auto n : name) { cout<<n<<endl; } return 0; }
这是完全错误的C++ 输入整数时如何中断for循环? #包括 #包括 使用名称空间std; int i; INTE; INTP; 字符名[10]={}; 不能像这样做吗- #include <iostream> #include <stdlib.h> using namespace std; int i; int e; int p; char name[10] = {}; cout<<endl<<"Please enter the letters of your name separated by enter, when you are done, type 'quit' "<<endl; for (e=0; e <= 10; e++) { cin>>name[e]; if (name[e] == 'quit') { break; } } for (p=0; p < ; p++) { cout<<name[p]; } return 0; } #包括 #包括 #包括 使用名称空间std; int i; INTE; INTP; 载体名称; 不能用a来表示。另外,使用std::string收集数据和检查输入的大小也会更容易。“quit”是一个字符串,它包含4个字符。不能将其视为单个字符。因此,必须使用双引号“”而不是单引号“”。 此外,此字符串保存在字符数组中,而不是单个字符变量中。所以 #include <iostream> #include <stdlib.h> #include <vector> using namespace std; int i; int e; int p; vector<string> name; cout<<endl<<"Please enter the letters of your name separated by enter, when you are done, type 'quit' "<<endl; while(1) { string tmp; cin>>tmp; if (tmp == "quit") { break; } else if(tmp.size()>10) { cout<<"Enter name with less then 11 character"<<endl; } else { name.push_back(tmp); } } for (auto n : name) { cout<<n<<endl; } return 0; },c++,iphone,for-loop,C++,Iphone,For Loop,这是完全错误的 if (name[e] == 'quit')
if (name[e] == 'quit')