网站建设收费标准效果,手机优化什么意思,网站500m空间价格,德州天元建设集团有限公司其实时间长了#xff0c;稍微研究后#xff0c;再来品味#xff0c;别有一番滋味 总是看着混乱#xff0c;但是静下来看#xff0c;还是能琢磨透的#xff0c;只是看着复杂#xff0c;本质是两套风格#xff0c;然后又要有交集#xff0c;所以就看起来复杂 // 首先字符… 其实时间长了稍微研究后再来品味别有一番滋味 总是看着混乱但是静下来看还是能琢磨透的只是看着复杂本质是两套风格然后又要有交集所以就看起来复杂 // 首先字符串 在c 风格叫字符串在c风格 叫字符数组//sizeof 获取对象大小、数据类型大小//strlen 用于获取以空字符 \0 结尾的字符串的长度 #include cstringC或 #include stringC// size 仅适用于C标准库的容器类用于获取容器中元素的数量//length 仅适用于C标准库的字符串类如 std::string用于获取字符串的长度。
// 其中length 和size的区别 前者是使用string 字符串 后者适用于所有C标准库的容器类包括 std::vector、std::list、std::set int main()
{char source[] Hello;char destination[2];char tem[128] {0};char tem2[128] {0};char tem3[128] {0};strncpy(destination, source, 3);for(int i 0; i sizeof(destination); i){std::coutdestination[i] std::endl;}strcpy(tem, destination);strncpy(tem2, destination, sizeof(destination));strncpy(tem3, destination, strlen(destination));//destination[5] \0;printf(\n);std::cout Destination: destination \ntem: tem\ntem2:tem2\ntem3:tem3std::endl;return 0;
}/*
输出
H
e Destination: Helello
tem: Helello
tem2:He
tem3:Helello
*//*
解答Destination对象分配的内存为2 所以字符数组只有两个字符 H etem 是完整的 destination数组 因为字符数组空间不够用所以没有在字符数组里面截断所以长度还是最开始的长度tem2 是截取 destination的两个元素tem3 截取的是destination 到 \0 的元素 也就是完整的字符串内容
*/