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++;_C++_String_Substring - Fatal编程技术网

C++ 如何在C++;

C++ 如何在C++;,c++,string,substring,C++,String,Substring,以下代码段显示了我当前输出的一小部分: 1464: ebfffe4d bl da0 <memcpy@plt> 14bc: ebfffe37 bl da0 <memcpy@plt> 1464:ebfffe4d bl da0 公元前14年:ebfffe37 bl da0 输出的每一行都引用一个字符串。我想说的是,在这个 仅案例memcpy@plt将打印一次。当字符串包含“bl”时,名称 内的名称相同,

以下代码段显示了我当前输出的一小部分:

1464:       ebfffe4d        bl      da0 <memcpy@plt>
14bc:       ebfffe37        bl      da0 <memcpy@plt>
1464:ebfffe4d bl da0
公元前14年:ebfffe37 bl da0
输出的每一行都引用一个字符串。我想说的是,在这个 仅案例memcpy@plt将打印一次。当字符串包含“bl”时,名称 内的名称相同,因此应打印且仅打印一次 在这两种情况下。有办法得到这个吗? 我当前的代码如下所示:

class CallFunction {
    private:
        vector<string> content;
    public:
        CallFunction(vector<string> content) {
            this->content = content;
        }
        void print() {
            for(string line: content) {
                if(line.find("bl") != std::string::npos
                && line.find("<") != std::string::npos) {
                    cout << line << endl;
                }
            }
        }
};

int main() {
    string fileName = "libndkmod.s";
    vector<string> content = readFile(fileName);
    CallFunction cf = CallFunction(content);
    cf.print();
}
类调用函数{
私人:
载体含量;
公众:
调用函数(向量内容){
这->内容=内容;
}
作废打印(){
for(字符串行:内容){
if(line.find(“bl”)!=std::string::npos

&&line.find(“我们可以使用
无序集
对子字符串进行重复数据消除,如果已经打印了相同的子字符串,则跳过它

此步骤可以提取为一种方法来遵循,这比在
打印
功能中处理复制更自然,此工作留给您

我们使用
unordered_set
而不是
std::set
,因为
unordered_set
将更快地搜索

我已经将for循环从
for(string-line:content)
更改为
for(const-string&line:content)
,然后我们避免了原始字符串的副本,以提高性能。基本上,除了原语类型之外,我们更喜欢对对象使用
for(const-auto&item:…)
,以避免副本

我们存储c++17中引入的
string\u视图
,以避免复制子字符串,它将节省内存,因为我们避免了不必要的复制


#包括
#包括
#包括
#包括
使用名称空间std;
类调用函数{
私人:
载体含量;
公众:
调用函数(向量内容){this->content=content;}
作废打印(){
std::无序集合成员;
for(常量字符串和行:内容){
自动左位置=行查找(“bl”);
自动右键位置=行。查找(“>”);
if(左位置!=std::string::npos&&right位置!=std::string::npos){
std::string_view sub_view={&line.front()+left_pos,
右位置-左位置+1};
如果(内存计数(子视图))继续;
成员插入(子视图);

是否可以将名称存储在集合中,仅当名称不在集合中时才打印行。或者将名称存储在集合中,然后只打印整个集合。名称是否会多次出现在连续行中?那么,您不需要集合,只需要当前条纹名称的单个变量。