トップ
新規
一覧
単語検索
最終更新
ヘルプ
ログイン
アールメカブ
CPP_vectorの使い方
をテンプレートにして作成
開始行:
[[Programming]]
#include <iostream>
#include <vector>
//#include <list>
using namespace std;
//vector<int> v;
void myadd(std::vector<int> &v, int x){
//void myadd(int x){
v.push_back(x);
//v.push_end(x);
}
int main(){
vector<int> v;
for(int i = 0; i < 5; i++)
v.push_back(i);
int x = 6;
vector<int>::iterator pv = v.begin();
while(pv != v.end()){
cout << *pv++ << ' ';
if(x < 10){
//cout << x << " in first loop" << endl;
myadd(v,x++);
// myadd(x++);
}
}
cout << endl;
while(pv != v.end()){
cout << *pv++ << ' ';
if(x < 10){
cout << x << " in second loop" << endl;
}
}
return 0;
}
ベクトルを引数として関数に渡す
#include
#include
using namespace std;
void myadd(std::vector <int> &v, int x){
v.push_back(x);
}
int main(){
}
vector<int> v;
for(int i = 0; i < 5; i++)
v.push_back(i);
int x = 6;
vector<int>::iterator pv = v.begin();
while(pv != v.end()){
cout << *pv++ << ' ';
if(x < 10){
cout << x << "in loop" << endl;
myadd(v,x++);
}
cout << endl;
return 0;
終了行:
[[Programming]]
#include <iostream>
#include <vector>
//#include <list>
using namespace std;
//vector<int> v;
void myadd(std::vector<int> &v, int x){
//void myadd(int x){
v.push_back(x);
//v.push_end(x);
}
int main(){
vector<int> v;
for(int i = 0; i < 5; i++)
v.push_back(i);
int x = 6;
vector<int>::iterator pv = v.begin();
while(pv != v.end()){
cout << *pv++ << ' ';
if(x < 10){
//cout << x << " in first loop" << endl;
myadd(v,x++);
// myadd(x++);
}
}
cout << endl;
while(pv != v.end()){
cout << *pv++ << ' ';
if(x < 10){
cout << x << " in second loop" << endl;
}
}
return 0;
}
ベクトルを引数として関数に渡す
#include
#include
using namespace std;
void myadd(std::vector <int> &v, int x){
v.push_back(x);
}
int main(){
}
vector<int> v;
for(int i = 0; i < 5; i++)
v.push_back(i);
int x = 6;
vector<int>::iterator pv = v.begin();
while(pv != v.end()){
cout << *pv++ << ' ';
if(x < 10){
cout << x << "in loop" << endl;
myadd(v,x++);
}
cout << endl;
return 0;
ページ名: