使用strlwr()和strupr()時會出現如下報錯信息:
‘strlwr’: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strlwr. See online help for details.
也就是strlwr()和strupr()已經被廢棄了,應當使用_strlwr()和_strupr()進行替換。
注意_strlwr()和_strupr()的參數爲char *類型,因此在處理單個字符的時候,需要傳入地址。
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
// 對單個字符進行轉換
char c = 'a';
_strlwr(&c); // 轉換爲小寫
cout << c << endl;
_strupr(&c); // 轉換爲大寫
cout << c << endl;
// 對字符串進行轉換
char s[100] = { "aaaBBBcccDDDeeeFFF" };
_strlwr(s); // 轉換爲小寫
cout << s << endl;
_strupr(s); // 轉換爲大寫
cout << s << endl;
return 0;
}
代碼運行結果:
a
A
aaabbbcccdddeeefff
AAABBBCCCDDDEEEFFF
謝謝閱讀