zoukankan      html  css  js  c++  java
  • std::strncpy 简介

    std::strncpy

     
    Defined in header <cstring>

     char *strncpy( char *dest, const char *src, std::size_t count );


    If count is reached before the entire string src was copied, the resulting character array is not null-terminated.Copies at most count characters of the byte string pointed to by src (including the terminating null character) to character array pointed to by dest.

    If, after copying the terminating null character from srccount is not reached, additional null characters are written todest until the total of count characters have been written.

    If the strings overlap, the behavior is undefined.

    Parameters

    dest    pointer to the character array to copy to

    src    pointer to the byte string to copy from

    count    maximum number of characters to copy

    Return value

    dest

    Example

     1 #include <iostream>
     2 #include <cstring>
     3 using namespace std;
     4 
     5 int main ()
     6 {
     7   char str1[]= "To be or not to be";
     8   char str2[6];
     9   strncpy (str2,str1,5);
    10   str2[5]='\0';
    11   cout<<str2;
    12   return 0;
    13 }

    Output:

    1  To be
    **************************************************************
    我喜欢程序员,他们单纯、固执、容易体会到成就感;面对困难,能够不休不眠;面对压力,能够迎接挑战。他们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想,用智慧把属于自己的事业开创。其实我是一个程序员
    [=.=]
  • 相关阅读:
    C++ Primer 笔记——标准库类型string
    Windows文件系统
    c++数组
    B+树
    简单搭建FastDFS分布式文件系统(简单易懂)
    什么是分布式系统(通俗易懂)
    对List中每个对象元素按时间顺序排序
    java23种设计模式之一: 策略模式
    微信app支付java后台流程、原理分析及nei网穿透
    quartz多任务调度+spring 实现
  • 原文地址:https://www.cnblogs.com/kevinGaoblog/p/2601293.html
Copyright © 2011-2022 走看看