[英]Is this a function or variable definition in c++ code?
我正在阅读一段 c++ 代码,其中 id、curi 和 len 是 integer,内容是字符串。 我不明白 match_word() 部分是什么。 它是 function 还是变量? 我在所有 header 文件中都找不到它的定义。
if(-1!=ids)
{
len = ids - curi;
string match_word(content, curi, len);
bool rejudge = false;
...
}
string match_word(content, curi, len);
这是/使用substring 构造函数
复制从字符 position curi 开始并跨越 len 个字符的内容部分(或者直到内容结尾,如果任一内容太短或 len 是 string::npos)。
所以例如
std::string s = "Hello World";
string match_word(s, 2, 7);
std::cout<<match_word<<std::endl; //prints llo Wor
以上将打印llo Wor
现在来回答你的问题:
这是 function 还是 c++ 代码中的变量定义?
基本上,这是使用 substring 构造函数的变量定义。 因此,在您的情况下, match_word
是std::string
类型的变量。
string match_word(content, curi, len);
match_word
是一个字符串。 这是一个声明。 看起来你想调用这个构造函数:
string (const string& str, size_t pos, size_t len = npos);
这是来自cplusplus的示例
#include <iostream>
#include <string>
int main()
{
std::string s0 ("Initial string");
std::string s3 (s0, 8, 3);
std::cout << s3;
}
这将打印:
str
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.