C++新手上路,vector初始化的有关问题,
C++新手上路,vector初始化的问题,急!
代码如下,大家不必看逻辑,看一下语法就行了。
编译通不过啊。一直报错:error: in C++98 ‘iv’ must be initialized by constructor, not by ‘{...}’
------解决思路----------------------
in C++98⋯⋯
很明显了吧
能这么写的是最新的C++
------解决思路----------------------
-std=c++11
------解决思路----------------------
------解决思路----------------------
把有限的生命浪费在品尝/品鉴无穷多种的语法糖中,我认为不值当。
代码如下,大家不必看逻辑,看一下语法就行了。
编译通不过啊。一直报错:error: in C++98 ‘iv’ must be initialized by constructor, not by ‘{...}’
#include<iostream>
#include<vector>
using namespace::std;
class Solution{
public:
vector<int> ivect;
int num;
Solution(vector<int> &a,int n):ivect(a),num(n) {}
int remove();
};
int Solution::remove()
{
int index = 1;
int i = 1;
for(i=index+1; i<num; i++){
if(index == num)
return index;
if(this->ivect[index] != this->ivect[i]){
++index;
this->ivect[index] = this->ivect[i];
}
}
return index;
}
int main()
{
int num;
vector<int> iv={1,1,2,3,4,5,5,5,6,6,6,7,7,7,7,7};
num = iv.size()/sizeof(iv[0]);
Solution solu(iv,num);
int i = 0;
int index = solu.remove();
for(i=0; i<= index; i++){
cout<<iv[i]<<endl;
}
return 0;
}
------解决思路----------------------
in C++98⋯⋯
很明显了吧
能这么写的是最新的C++
------解决思路----------------------
-std=c++11
------解决思路----------------------
g++ -std=c++11
------解决思路----------------------
把有限的生命浪费在品尝/品鉴无穷多种的语法糖中,我认为不值当。