Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用子字符串的位置作为起点来显示字符串的内容?_C++_String_Find - Fatal编程技术网

C++ 如何使用子字符串的位置作为起点来显示字符串的内容?

C++ 如何使用子字符串的位置作为起点来显示字符串的内容?,c++,string,find,C++,String,Find,是否可以将字符串从使用string.find获得的位置拖到字符串的末尾。std::coutstd::cout这当然是可能的,而且有多种方式string.find()返回一个位置,所以 std::cout << yourStr.substr(yourStr.find("position")); #include <iostream> #include <string> int main() { std::string str = "This is a

是否可以将字符串从使用string.find获得的位置拖到字符串的末尾。

std::cout
std::cout这当然是可能的,而且有多种方式
string.find()
返回一个位置,所以

std::cout << yourStr.substr(yourStr.find("position"));
#include <iostream>
#include <string>
int main()
{
    std::string str = "This is a test";
    std::string::size_type pos = str.find("test");
    if(pos != std::string::npos)
        std::cout << str.substr(pos) << '\n';
}

这当然是可能的,而且有多种方式
string.find()
返回一个位置,所以

#include <iostream>
#include <string>
int main()
{
    std::string str = "This is a test";
    std::string::size_type pos = str.find("test");
    if(pos != std::string::npos)
        std::cout << str.substr(pos) << '\n';
}

当然
string::find
返回一个索引,并且
string::substr
为起始位置(和结束位置,但在本例中可以使用默认位置)获取一个索引,因此可以执行以下操作:

std::cout << mystring.substr(mystring.find("Whatever"));

std::cout当然
string::find
返回一个索引,并且
string::substr
为起始位置(和结束位置,但在本例中可以使用默认位置)获取一个索引,因此可以执行以下操作:

std::cout << mystring.substr(mystring.find("Whatever"));
std::cout返回字符串中索引的大小,它在该字符串中查找您正在搜索的内容。如果它不是
npos
,您可以将其替换为:

size_t pos = str.find("whatever");
if (pos != std::string::npos) {
  std::cout << str.substr(pos);
}
size\u t pos=str.find(“任意”);
if(pos!=std::string::npos){
std::cout返回字符串中索引的大小,在该字符串中它可以找到您正在搜索的内容。如果它不是
npos
,您可以将其替换为:

size_t pos = str.find("whatever");
if (pos != std::string::npos) {
  std::cout << str.substr(pos);
}
size\u t pos=str.find(“任意”);
if(pos!=std::string::npos){
std::cout
#包括
#包括
使用名称空间std;
int main(){
常量字符串s(“无论多远都如此接近”);
常量字符串::size_type pos=s.find(“否”);
if(pos!=字符串::npos){
不能包含
#包括
使用名称空间std;
int main(){
常量字符串s(“无论多远都如此接近”);
常量字符串::size_type pos=s.find(“否”);
if(pos!=字符串::npos){
库特