zoukankan      html  css  js  c++  java
  • strcspn函数与basic_istream::gcount 函数

    size_t strcspn ( const char * str1, const char * str2 );

    Get span until character in string

    Scans str1 for the first occurrence of any of the characters that are part of str2, returning the number of characters of str1 read before this first occurrence.

    The search includes the terminating null-characters, so the function will return the length of str1 if none of the characters of str2 are found in str1.

    Parameters

    str1
    C string to be scanned.
    str2
    C string containing the characters to match.

    Return value

    The length of the initial part of str1 not containing any of the characters that are part of str2.
    This is the length of str1 if none of the characters in str2 are found in str1.

     1 /* strcspn example */
    2 #include <stdio.h>
    3 #include <string.h>
    4
    5 int main ()
    6 {
    7 char str[] = "fcba73";
    8 char keys[] = "1234567890";
    9 int i;
    10 i = strcspn (str,keys);
    11 printf ("The first number in str is at position %d.\n",i+1);
    12 return 0;
    13 }

    Output:

    The first number in str is at position 5
     
     
     
    basic_istream::gcount 

    Returns the number of characters read during the last unformatted input. 

    streamsize gcount( ) const;

    Return Value

    The extraction count.

    Remarks

    Useto read unformatted characters. 

     1 // basic_istream_gcount.cpp
    2 // compile with: /EHsc
    3 #include <iostream>
    4 using namespace std;
    5
    6 int main( )
    7 {
    8 cout << "Type the letter 'a': ";
    9
    10 ws( cin );
    11 char c[10];
    12
    13 cin.get( &c[0],9 );
    14 cout << c << endl;
    15
    16 cout << cin.gcount( ) << endl;
    17 }
    Type the letter 'a':
    a
    1






  • 相关阅读:
    linux反汇编
    Java中UML图
    Java设计模式_创建型模式_单例模式
    Javadoc注释的用法
    VIM使用技巧1
    手动破解的 Linux下的Maltab 2014b
    让vim的在输入模式下现实光标不同
    Vim 自动补全成对的括号和引号
    MAMP:在 OSX 中搭建 Apache, MySQL, PHP 环境并本地安装、调试 WordPress
    MAC+iTerm定制目录显示颜色和提示符
  • 原文地址:https://www.cnblogs.com/kex1n/p/2315012.html
Copyright © 2011-2022 走看看