かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

[C++][STL]久しぶりに触ってみたけど素敵だ

C++に長久しぶりに触ってみた。
C++は標準ライブラリが貧相なので、最近小物を作ったりするのにつかってなかったけど復帰してみようかなぁ。

昔は暗記してたSTLも、ほとんど忘却の彼方。
ということで、ちょびっとだけ復習をしてみよう。

第一弾!!
コンテナの部からstd::vector<T>
アルゴリズムの部からstd::sort
イテレータの部からstd::istream_iterator<T>, std::ostream_iterator<T>

ついでに、C++/CLIのプロジェクト内でさくっと使えるのか試してみる。(問題は無いんだろうけど)

コンソールのプロジェクトをさくっと作成。
stdafx.hに下のincludeを追加する。

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

そういえば、何を作るか言ってなかった。
キーボードからCtrl + Zが入力されるまで、数値を読み込んでいく。んで、ソートして出力!
超簡単プログラム。思い出すにはちょうどいい!

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
	std::vector<int> v;
	std::copy(std::istream_iterator<int, wchar_t>(std::wcin), 
		std::istream_iterator<int, wchar_t>(),
		std::back_insert_iterator<std::vector<int> >(v));
	std::sort(v.begin(), v.end());
	std::copy(v.begin(), v.end(), std::ostream_iterator<int, wchar_t>(std::wcout, L" "));
    return 0;
}

可も無く不可も無くといった感じ。
std::back_insert_iteratorとかよく覚えてたな自分。

投稿日時 : 2008年2月26日 0:44

Feedback

# re: [C++][STL]久しぶりに触ってみたけど素敵だ 2008/02/26 9:17 επιστημη

↓back_inserterを排除してみるテスト:
int main() {
 typedef std::istream_iterator<int, wchar_t> input;
 std::vector<int> v((input)(std::wcin), input());
// 以下同文

# re: [C++][STL]久しぶりに触ってみたけど素敵だ 2008/02/27 9:04 かずき

vectorにはiteratorを受け取るコンストラクタがありましたね!
忘れてました...orz

επιστημηのSTL標準講座を読み直さなきゃ。

# ShoaOockTSuzBQ 2011/12/23 0:17 http://247options.com/

The Author is crazy..!

# nNpkzZYjcjYCubMST 2011/12/23 18:30 http://247options.com/

Scribbler, give me a student's record-book!)))

# mTViybvdCUsJJ 2012/01/04 6:45 http://www.kosherbeefjerky.net/

56wx65 Post brought me to think, went to mull over!!...

# sac longchamp 2012/10/19 15:27 http://www.sacslongchamppascher2013.com

Regards for helping out, wonderful information. "I have witnessed the softening of the hardest of hearts by a simple smile." by Goldie Hawn.

# louis vuitton diaper bag 2012/10/28 3:22 http://www.louisvuittonoutletdiaperbag.com/

Joy and happiness is really scent you are unable to dump regarding other individuals and it doesn't involve obtaining handful sheds regarding your true self.
louis vuitton diaper bag http://www.louisvuittonoutletdiaperbag.com/

# burberry outlet 2012/11/02 22:23 http://www.burberryoutletonlineshopping.com/

Appreciate it for helping out, wonderful information. "Those who restrain desire, do so because theirs is weak enough to be restrained." by William Blake.
burberry outlet http://www.burberryoutletonlineshopping.com/

# cheap burberry bags 2012/11/03 0:01 http://www.burberrysalehandbags.com/burberry-tote-

I like this post, enjoyed this one thanks for posting .
cheap burberry bags http://www.burberrysalehandbags.com/burberry-tote-bags.html

# Burberry Tie 2012/11/03 0:01 http://www.burberrysalehandbags.com/burberry-ties.

I consider something really special in this website.
Burberry Tie http://www.burberrysalehandbags.com/burberry-ties.html

タイトル
名前
Url
コメント