#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> ivec;
int a;
while (cin >> a)
{
ivec.push_back(a);
}
int *p = new int[ivec.size()];
int *q = p;//这条语句如果放在for循环里面会出错,放在外面就没事???
for(vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); iter++, q++)
{
*q = *iter;
}
for (size_t i = 0; i != ivec.size(); i++)
{
cout << *(p + i) << endl;
}
delete [] p;
return 0;
}
F:\C++primer练习\第四章\28.cpp(34) : warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
F:\C++primer练习\第四章\28.cpp(34) : error C2440: 'initializing' : cannot convert from 'int *' to 'int ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
F:\C++primer练习\第四章\28.cpp(34) : warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
F:\C++primer练习\第四章\28.cpp(34) : error C2146: syntax error : missing ')' before identifier 'iter'
F:\C++primer练习\第四章\28.cpp(34) : warning C4552: '!=' : operator has no effect; expected operator with side-effect
F:\C++primer练习\第四章\28.cpp(34) : error C2059: syntax error : ';'
F:\C++primer练习\第四章\28.cpp(34) : error C2059: syntax error : ')'
F:\C++primer练习\第四章\28.cpp(35) : error C2143: syntax error : missing ';' before '{'
F:\C++primer练习\第四章\28.cpp(36) : error C2440: '=' : cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
28.obj - 1 error(s), 0 warning(s)