Strcspn function and basic_istream: gcount Function

Source: Internet
Author: User
Document directory
  • Parameters
  • Return value
size_t strcspn ( const char * str1, const char * str2 );

Get span until character in string

ScansStr1For the first occurrence of any of the characters that are partStr2, Returning the number of charactersStr1Read before this first occurrence.

The search criteria des the terminating null-characters, so the function will return the lengthStr1If none of the charactersStr2Are found inStr1.

Parameters
Str1
C string to be scanned.
Str2
C string containing the characters to match.

 

Return value

The length of the initial partStr1 NotContaining any of the characters that are partStr2.
This is the lengthStr1If none of the characters inStr2Are found inStr1.

 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':a1


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.