std::strcspn
來自 cppreference.com
在標頭檔案 <cstring> 中定義 |
||
std::size_t strcspn( const char *dest, const char *src ); |
||
返回指向 dest 的位元組字串的最大初始段的長度,該段僅包含在指向 src 的位元組字串中未找到的字元。
函式名稱代表“補餘跨度”。
目錄 |
[編輯] 引數
dest | - | 指向要分析的以空字元結尾的位元組字串的指標 |
src | - | 指向包含要搜尋的字元的以空字元結尾的位元組字串的指標 |
[編輯] 返回值
最大初始段的長度,該段僅包含在指向 src 的位元組字串中未找到的字元。
[編輯] 示例
執行此程式碼
#include <cstddef> #include <cstring> #include <iomanip> #include <iostream> #include <string> int main() { std::string s = "abcde312$#@"; const char* invalid = "*$#"; const std::size_t valid_len = std::strcspn(s.c_str(), invalid); if (valid_len != s.size()) { std::cout << std::quoted(s) << " contains invalid chars starting at position " << valid_len << '\n' << std::string(valid_len + 1, '-') << "^\n"; } }
輸出
"abcde312$#@" contains invalid chars starting at position 8 ---------^
[編輯] 參閱
返回由另一個位元組字串中找到的字元組成的最大初始段的長度 的字元 (函式) | |
返回由另一個位元組字串中找到的字元組成的最大初始段的長度 僅當另一個寬字串中未找到寬字元時 (函式) | |
查詢分隔符集中任何字元的第一個位置 (函式) | |
查詢字元的首次出現 ( std::basic_string<CharT,Traits,Allocator> 的公共成員函式) | |
C 文件 用於 strcspn
|