c++ - C++ 我应该使用什么类型的指针来存储“算法”“删除”函数的输出地址?
问题描述
我试图将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
如果您不想明确指定类型,可以使用关键字。
推荐阅读
- javascript - 在nodejs中没有异步调用第二个函数
- python - 通用递归函数
- azure - Azure 更新管理解决方案的代理就绪状态在移动到不同的订阅后显示断开连接。如何更改状态?
- apache-nifi - NIFI - 如何嵌套解压缩并保持相同的目录结构
- flutter - Flutter Button 与简单代码不匹配
- r - 如何将 2x2 列联表粘贴到 rstudio?
- pytorch - Tensorboard:使用自定义 x 值
- reactjs - 当我单击按钮时如何在数据处理时显示加载屏幕 - React js
- git - 我在写“git”时尝试了“push”。但是,以下消息并不能解决问题。我该如何解决?
- error-handling - 为什么显示 Errno2 没有这样的文件目录,但文件在同一目录中?