我试图将algorithm removeC++ 中函数返回的地址存储在一个变量中,但未能找到。我试过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);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试 C++ 上的链接列表,当我尝试打印列表的数据时,它给出了有趣的结果,告诉我列表为空。当我在 main 中打印变量的地址和在函数中打印同一变量的参数地址时,会给出不同的结果。有谁可以帮我解释一下吗,谢谢!这是代码:
#include <iostream>
using namespace std;
typedef struct link_node{
int data;
link_node* next;
};
void iter(link_node* head){
link_node* cur = head;
cout<<"The address of head in function: "<<&head<<endl;
while(cur!=NULL){
cur = cur->next;
cout<<cur->data<<' ';
}
}
link_node *create(int a){
link_node* head;
link_node* cur;
head =(link_node*) malloc(sizeof(link_node));
cur = head;
for(int i=a;i<a+10;i+=2){
link_node * node = (link_node*) malloc(sizeof(link_node));
node->data = i;
cur->next = node;
cur = node;
}
cur->next = NULL;
return head;
}
int main(){
link_node* …Run Code Online (Sandbox Code Playgroud)