簡體   English   中英

c++ 中是否有像 javascript 中那樣的“includes()”方法

[英]Is there an “includes()” method in c++ like there is in javascript

我一直試圖從 c++ 中的另一個字符串中獲取特定字符串,我想知道是否有像 javascript 中那樣的“includes()”方法,如果字符串參數在另一個指定的字符串中,則返回 true。 如果不是,那么最接近它的東西是什么?

這個問題的重復。

std::string::find function 將返回字符串內“子字符串”的 position。 如果未找到 substring,則返回std::string::npos

一個includes() function 可能看起來像:

bool includes(const std::string &str, const std::string &subStr) {
    return (str.find(subStr) != std::string::npos);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM