两个if和下面cout代码的顺序有影响没,老师为啥没有按1,2,3,4,5,的顺序给出代码,而是先把两个判断提前了?
好心的小伙伴帮忙看看代码

好心的小伙伴帮忙看看代码

2018-08-05
#include <iostream>
#include<string>
using namespace std;
int main()
{
cout << "pleas enter your name" << endl;
string s1;
getline(cin, s1);
if (s1.empty())
{
cout << "this is empty" << endl;
return 0;
}
cout << "hello " << s1 << endl;
if (s1 == "imooc")
{
cout << "you are the admin" << endl;
}
cout << "your name is : " << s1.size() << " characters" << endl;
cout << "the first character of you name is : " << s1[0] << endl;
return 0;
}#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
int main(){
string name;
cout<< "Please input your name:" << endl;
getline(cin,name);
if (name.empty()){
cout <<"input is NULL." << endl;
system("pause");
return 0;
}
if (name == "imooc"){
cout << "you are a administrator." << endl;
}
cout << "hello " + name << endl;
cout << "the length of your name:" << name.size() <<endl;
cout << "the first letter of your name:" << name[0] <<endl;
system("pause");
return 0;
}举报