gpt4 book ai didi

C++ 我应该使用什么类型的指针来存储 `algorithm` `remove` 函数的输出地址?

转载 作者:行者123 更新时间:2023-12-01 14:37:07 25 4
gpt4 key购买 nike

我正在尝试存储 algorithm 返回的地址remove C++ 中的函数在一个变量中,但未能找到一个。我试过int*char* 。两者都抛出错误。

使用Visual Studio CL,错误是: error C2440: '=': cannot convert from '_FwdIt' to 'int *'

使用MinGW,错误为: cannot convert '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' to 'int*' in assignment

我应该如何存储这样的地址?

我正在尝试的代码:

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main (void) {
string line ("This is an example sentence.");
int* newEOL;
newEOL = remove(line.begin(), line.end(), ' ');
printf("%p\n", newEOL);
}

最佳答案

为什么你认为它是一个指针?

如下所示:https://en.cppreference.com/w/cpp/algorithm/remove它是一个迭代器,可以实现为指针,但不是必须的。

如果您不想显式指定类型,可以使用 auto 关键字。

关于C++ 我应该使用什么类型的指针来存储 `algorithm` `remove` 函数的输出地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63279022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com