有什么辦法解決輸入漢字時的首個漢字無法輸出的問題
/*************************************************************************/
/*題目描述:
? ? ? ? ? ?1. 提示用戶輸入姓名
? 2. 接收用戶的輸入
? 3. 然后向用戶問好, hello xxx
? 4. 告訴用戶名字的長度
? 5. 告訴用戶名字的首字母是什么
? 6. 如果用戶直接輸入回車那么告訴用戶的輸入為空
? 7. 如果用戶輸入的是imooc,那么告訴用戶的角色是一個管理員*/
#include"stdafx.h"
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
int main()
{
string name;
cout << "please input your name:" << name;
getline(cin, name);
if (name.empty())
{
cout << "input is null..." << endl;
return 0;
}
if (name == "imooc")
cout << "you are a administrator" << endl;
cout << "your name length :" << name.size() << endl;
cout << "your name first letter is :" << name[0] << endl;
return 0;
}
//未成熟版本 :漢字無法正常使用 輸入漢字時 一個漢字相當(dāng)于兩個字母長度 首字母無法輸出
2016-04-10
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
int main()
{
string name;
cout << "please input your name:" << name;
getline(cin, name);
if (name.empty())
{
cout << "input is null..." << endl;
return 0;
}
if (name == "imooc")
cout << "you are a administrator" << endl;
cout << "your name length :" << name.size() << endl;
cout << "your name first letter is :" << name[0] <<name[1]<< endl;
return 0;
}
2017-11-23
為啥name【1】就可以打出第一個中文???還有個數(shù)為啥錯了?
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
int main(void)
{
string name;
cout << "please input your name :" << endl;
getline(cin, name);
if (name.empty())
{
cout << "please input your name:" << endl;
}
if (name == "imooc")
{
cout << "you are a administrator" << endl;
system("pause");
return 0;
}
cout << "hello" << " ?" << name << endl;
cout << "your name length is :" << name.size() << endl;
cout << "your name first letter is :" << name[0] << name[1] << endl;
system("pause");
return 0;
}
2016-11-06
為什么加了name【1】就可以打出第一個中文???