⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hour15_4.cpp

📁 C++学习的有利助手
💻 CPP
字号:
 // Listing 15.9 Using strncpy()
 #include <iostream>
 #include <string.h>

 int main()
 {
     const int MaxLength = 80;
     char String1[] = "No man is an island";
     char String2[MaxLength+1];

     strncpy(String2,String1,5);              // limited to 5 rather than MaxLength
     String2[strlen(String1)] = '\0'; // add a null to the end
     std::cout << "String1: " << String1 << std::endl;
     std::cout << "String2: " << String2 << std::endl;

// you should see how strncpy can limit the length that you copy to a smaller
// portion of the string. This can come in handy when you want to subset something

     return 0;
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -