using namespace std
class Person
{
mutable int m_A
}
void test01()
{
cout << "********strcpy_s 拷贝全部***********" << endl
char a[] = "abcdefg"
char b[sizeof(a)]
strcpy_s(b, sizeof(a), a)
cout << b << endl
cout << endl << "*********strncpy_s 拷贝部分**********" << endl
strncpy_s(b, a,3)
cout << b << endl
cout << sizeof(b) << endl
cout << endl << "*********strcmp 比较字符串**********" << endl
char str1[] = "abc"
char str2[] = "abc"
auto rst = strcmp(str1, str2)
cout << rst << endl
cout << typeid(rst).name() << endl
cout << endl << "*********strcat_s 连接字符串**********" << endl
char str3[22] = "hello"
char str4[] = " world"
auto rst1 = strcat_s(str3,22, str4)
cout << rst1 << endl
cout << str3 << endl
cout << str4 << endl
cout << endl << "******strchr 查找字符串中第一次出现的字符*************" << endl
char str5[] = "good luck"
auto rst2 = strchr(str5, 'l')
cout << rst2 << endl
cout << endl << "******strstr 查找字符串中第一次出现的子字符串*************" << endl
char str6[] = "good luck"
auto rst3 = strstr(str6, "od")
cout << rst3 << endl
}
void test02() {
cout << endl << "******size() length() 求字符串长度*************" << endl
string str1 = "abcde"
cout << sizeof(str1) << endl
cout << str1.size() << endl
cout << str1.length() << endl
cout << endl << "******append +追加*************" << endl
string str2 = "hello"
str2.append(" world")
cout << str2 << endl
str2 += " ni hao"
cout << str2 << endl
cout << endl << "******substr 提取字符串*************" << endl
string str3 = "hello"
string rst1 = str3.substr(0,2)
cout << str3 << endl
cout << rst1 << endl
cout << endl << "******find 查找字符串或者字符串第一次出现的位置*************" << endl
string str4 = "hellolloe"
size_t rst2 = str4.find('e')
size_t rst3 = str4.find("ll")
cout << typeid(rst2).name() << endl
cout << rst2 << endl
cout << rst3 << endl
cout << endl << "******compare 比较字符串*************" << endl
string str5 = "hellolloe"
string str6 = "zellolloe"
auto rst4 = str5.compare(str6)
cout << rst4 << endl
cout << endl << "******c_str() 比较字符串*************" << endl
string str7 = "hellolloe"
const char * ch1 = str7.c_str()
cout << ch1 << endl
cout << typeid(ch1).name() << endl
}
typedef LONG(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW)
DWORD IsWindows11OrGreater() {
HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll")
if (hMod) {
RtlGetVersionPtr RtlGetVersion = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion")
if (RtlGetVersion != nullptr) {
RTL_OSVERSIONINFOW rovi = { 0 }
rovi.dwOSVersionInfoSize = sizeof(rovi)
if (RtlGetVersion(&rovi) == 0) { // 0 means success
// Windows 11 has a major version of 10 and a build number of 22000 or greater
//return (rovi.dwMajorVersion == 10 && rovi.dwBuildNumber >= 22000)
return rovi.dwBuildNumber
}
}
}
return 0
}
void test03()
{
std::cout << IsWindows11OrGreater() << std::endl
}
int main() {
test03()
system("pause")
// 程序退出时自动检测未释放的内存
return 0
}