C++ primer 第四章(一)
#include <iostream>
#include <string>
#include <istream>
#include <vector>
using std::istream;
using std::cin;
using std::cerr;
using std::string;
using std::cout;
using std::endl;
using std::vector;
void main()
{
//3.18
const int count=10;
int value(0);
vector<int> ivec;
for(int i=0;i<count;++i)
{
cin>>value;
ivec.push_back(value);
}
for(vector<int>::iterator i=ivec.begin();i!=ivec.end();++i)
{
cout<<(*i)*2<<endl;
}
//4.7
const int nums=6;
int array1[]={1,2,3,4,5,6};
int array2[nums];
vector<int> vec1;
vector<int> vec2;
int value(0);
for(string::size_type i=0;i!=nums;++i)
{
array2[i]=array1[i];
}
while(cin>>value)
{
vec1.push_back(value);
}
for(vector<int>::iterator i=vec1.begin();i!=vec1.end();++i)
{
vec2.push_back(*i);
}
//4.8
const int arraylen=5;
int arr1[arraylen];
int arr2[arraylen];
int value(0);
for(int i=0;i!=arraylen;++i)
{
cin>>arr1[i];
}
for(int i=0;i!=arraylen;++i)
{
cin>>arr2[i];
}
for(int i=0;i!=arraylen;++i)
{
if(arr1[i]!=arr2[i])
{
cout<<"两数组不相等@";
return ;
}
}
cout<<"两数组相等!";
//4.9
int num2s[10];
for(int i=0;i<10;++i)
{
num2s[i]=i+1;
cout<<num2s[i]<<" ";
}
//4.14
int * pi=0;
int num=90;
cout<<pi;
pi=#
cout<<endl<<pi;//改变PI的值
*pi=89;
cout<<endl<<*pi;//改变所指对象的值
//4.15
const size_t len=6;
int nums[len]={0,1,2,3,4,5};
for(int *pbegin=nums, *pend=nums+len;pbegin!=pend;++pbegin)
{
*pbegin=0;
}
//4.28
vector<int> vec;
int num(0);
while(cin>>num)
{
vec.push_back(num);
}
const size_t len=vec.size();
int *values=new int[len];
for(size_t i=0;i!=len;++i)
{
values[i]=vec[i];
}
system("pause");
}