東方算程譚

Oriental Code Talk ── επιστημηが与太をこく、弾幕とは無縁のシロモノ。

目次

Blog 利用状況

ニュース

著作とお薦めの品々は

著作とお薦めの品々は
東方熱帯林へ。

あわせて読みたい

わんくま

  1. 東京勉強会#2
    C++/CLI カクテル・レシピ
  2. 東京勉強会#3
    template vs. generics
  3. 大阪勉強会#6
    C++むかしばなし
  4. 東京勉強会#7
    C++むかしばなし
  5. 東京勉強会#8
    STL/CLRによるGeneric Programming
  6. TechEd 2007 @YOKOHAMA
    C++・C++/CLI・C# 適材適所
  7. 東京勉強会#14
    Making of BOF
  8. 東京勉強会#15
    状態遷移
  9. 名古屋勉強会#2
    WinUnit - お気楽お手軽UnitTest

CodeZine

  1. Cで実現する「ぷちオブジェクト指向」
  2. CUnitによるテスト駆動開発
  3. SQLiteで組み込みDB体験(2007年版)
  4. C++/CLIによるCライブラリの.NET化
  5. C# 1.1からC# 3.0まで~言語仕様の進化
  6. BoostでC++0xのライブラリ「TR1」を先取りしよう (1)
  7. BoostでC++0xのライブラリ「TR1」を先取りしよう (2)
  8. BoostでC++0xのライブラリ「TR1」を先取りしよう (3)
  9. BoostでC++0xのライブラリ「TR1」を先取りしよう (4)
  10. BoostでC++0xのライブラリ「TR1」を先取りしよう (5)
  11. C/C++に対応した、もうひとつのUnitTestFramework ─ WinUnit
  12. SQLiteで"おこづかいちょう"
  13. STL/CLRツアーガイド
  14. マージ・ソート : 巨大データのソート法
  15. ヒープソートのアルゴリズム
  16. C++0xの新機能「ラムダ式」を次期Visual Studioでいち早く試す
  17. .NETでマンデルブロ集合を描く
  18. .NETでマンデルブロ集合を描く(後日談)
  19. C++/CLI : とある文字列の相互変換(コンバージョン)
  20. インテルTBBによる選択ソートの高速化
  21. インテルTBB3.0 によるパイプライン処理
  22. Visual C++ 2010に追加されたSTLアルゴリズム
  23. Visual C++ 2010に追加されたSTLコンテナ「forward_list」
  24. shared_ptrによるObserverパターンの実装
  25. .NETでマンデルブロ集合を描く(番外編) ── OpenCLで超並列コンピューティング
  26. StateパターンでCSVを読む
  27. 状態遷移表からStateパターンを自動生成する
  28. 「ソートも、サーチも、あるんだよ」~標準C++ライブラリにみるアルゴリズムの面白さ
  29. インテルTBBの同期メカニズム
  30. なぜsetを使っちゃいけないの?
  31. WPFアプリケーションで腕試し ~C++でもWPFアプリを
  32. C++11 : スレッド・ライブラリひとめぐり
  33. Google製のC++ Unit Test Framework「Google Test」を使ってみる
  34. メールでデータベースを更新するココロミ
  35. Visitorパターンで遊んでみたよ
  36. Collection 2題:「WPFにバインドできる辞書」と「重複を許す検索set」
  37. Visual C++ 2012:stateless-lambdaとSQLiteのぷち拡張
  38. 「Visual C++ Compiler November 2012 CTP」で追加された6つの新機能

@IT

  1. Vista時代のVisual C++の流儀(前編)Vista到来。既存C/C++資産の.NET化を始めよう!
  2. Vista時代のVisual C++の流儀(中編)MFCから.NETへの実践的移行計画
  3. Vista時代のVisual C++の流儀(後編) STL/CLRによるDocument/Viewアーキテクチャ
  4. C++開発者のための単体テスト入門 第1回 C++開発者の皆さん。テスト、ちゃんとしていますか?
  5. C++開発者のための単体テスト入門 第2回 C++アプリケーションの効率的なテスト手法(CppUnit編)
  6. C++開発者のための単体テスト入門 第3回 C++アプリケーションの効率的なテスト手法(NUnit編)

AWARDS


Microsoft MVP
for Visual Developer - Visual C++


Wankuma MVP
for いぢわる C++


Nyantora MVP
for こくまろ中国茶

Xbox

Links

記事カテゴリ

書庫

日記カテゴリ

バイナリ読み書き

ネタ元 → fwriteについて

vector<char> のナカミをバイナリファイルにごそっと書き込みたいらしい。
んでもって fwrite の使い方でぢたばたしておったようです。

えとね、<fstream> <algorithm> <iterator> のコンビネーションでさっくり書けるですよ♪

#include <fstream>   // [io]fstream
#include <algorithm> // copy, equal
#include <vector>    // vector
#include <list>      // list
#include <iterator>  // [io]streambuf_iterator
#include <cstdlib>   // rand
#include <cassert>   // assert

using namespace std;

int main() {

  vector<char> src;
  // 五万文字ほどテケトーに埋める
  for ( int i = 0; i < 50000; ++i ) {
    src.push_back(static_cast<char>(rand()));
  }
 
  // 書き込みオープンし、
  ofstream ostrm("test.dat", ios::binary);
  // そいつのstream_bufに直接ぶっこむ: copy一発♪
  copy(src.begin(), src.end(), ostreambuf_iterator<char>(ostrm));
  ostrm.close();
 
  // 読み込みオープンし、
  ifstream istrm("test.dat", ios::binary);
  // istreambufから直接list<char>を生成してまう。
  list<char> dst((istreambuf_iterator<char>(istrm)),
                
(istreambuf_iterator<char>()));
  istrm.close();

  // うまくいったかな?
  assert( src.size() == dst.size() );
  assert( equal(src.begin(), src.end(), dst.begin()) );
}

[追記] 投稿ボタン押したとたんに
.Text - Application Error ! とか
Service Unavailable とか... なんかヘン > くまさばちゃん

投稿日時 : 2009年1月9日 12:00

コメントを追加

# re: バイナリ読み書き 2009/01/09 14:25 p

ビューティフォー

# re: バイナリ読み書き 2009/01/09 14:40 επιστημη

せんきゅー♪

# Everyone loves it when people come together and share opinions. Great blog, stick with it! 2021/09/01 6:24 Everyone loves it when people come together and sh

Everyone loves it when people come together and share opinions.
Great blog, stick with it!

# Everyone loves it when people come together and share opinions. Great blog, stick with it! 2021/09/01 6:25 Everyone loves it when people come together and sh

Everyone loves it when people come together and share opinions.
Great blog, stick with it!

# Everyone loves it when people come together and share opinions. Great blog, stick with it! 2021/09/01 6:26 Everyone loves it when people come together and sh

Everyone loves it when people come together and share opinions.
Great blog, stick with it!

# Everyone loves it when people come together and share opinions. Great blog, stick with it! 2021/09/01 6:27 Everyone loves it when people come together and sh

Everyone loves it when people come together and share opinions.
Great blog, stick with it!

# Hey! Someone in my Facebook group shared this website with us so I came to look it over. I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers! Exceptional blog and superb design and style. 2021/09/02 7:35 Hey! Someone in my Facebook group shared this webs

Hey! Someone in my Facebook group shared this website with us so
I came to look it over. I'm definitely loving the information. I'm
bookmarking and will be tweeting this to my followers!
Exceptional blog and superb design and style.

# Hey! Someone in my Facebook group shared this website with us so I came to look it over. I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers! Exceptional blog and superb design and style. 2021/09/02 7:36 Hey! Someone in my Facebook group shared this webs

Hey! Someone in my Facebook group shared this website with us so
I came to look it over. I'm definitely loving the information. I'm
bookmarking and will be tweeting this to my followers!
Exceptional blog and superb design and style.

# Hey! Someone in my Facebook group shared this website with us so I came to look it over. I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers! Exceptional blog and superb design and style. 2021/09/02 7:37 Hey! Someone in my Facebook group shared this webs

Hey! Someone in my Facebook group shared this website with us so
I came to look it over. I'm definitely loving the information. I'm
bookmarking and will be tweeting this to my followers!
Exceptional blog and superb design and style.

# Hey! Someone in my Facebook group shared this website with us so I came to look it over. I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers! Exceptional blog and superb design and style. 2021/09/02 7:38 Hey! Someone in my Facebook group shared this webs

Hey! Someone in my Facebook group shared this website with us so
I came to look it over. I'm definitely loving the information. I'm
bookmarking and will be tweeting this to my followers!
Exceptional blog and superb design and style.

# My brother recommended I might like this website. He was entirely right. This post truly made my day. You can not imagine just how much time I had spent for this info! Thanks! 2021/09/02 23:57 My brother recommended I might like this website.

My brother recommended I might like this website. He was
entirely right. This post truly made my day. You
can not imagine just how much time I had spent for this info!

Thanks!

# My brother recommended I might like this website. He was entirely right. This post truly made my day. You can not imagine just how much time I had spent for this info! Thanks! 2021/09/02 23:59 My brother recommended I might like this website.

My brother recommended I might like this website. He was
entirely right. This post truly made my day. You
can not imagine just how much time I had spent for this info!

Thanks!

# My brother recommended I might like this website. He was entirely right. This post truly made my day. You can not imagine just how much time I had spent for this info! Thanks! 2021/09/03 0:00 My brother recommended I might like this website.

My brother recommended I might like this website. He was
entirely right. This post truly made my day. You
can not imagine just how much time I had spent for this info!

Thanks!

# My brother recommended I might like this website. He was entirely right. This post truly made my day. You can not imagine just how much time I had spent for this info! Thanks! 2021/09/03 0:01 My brother recommended I might like this website.

My brother recommended I might like this website. He was
entirely right. This post truly made my day. You
can not imagine just how much time I had spent for this info!

Thanks!

# It's fantastic that you are getting thoughts from this post as well as from our discussion made here. 2021/09/04 20:50 It's fantastic that you are getting thoughts from

It's fantastic that you are getting thoughts from this post as
well as from our discussion made here.

# It's fantastic that you are getting thoughts from this post as well as from our discussion made here. 2021/09/04 20:51 It's fantastic that you are getting thoughts from

It's fantastic that you are getting thoughts from this post as
well as from our discussion made here.

# It's fantastic that you are getting thoughts from this post as well as from our discussion made here. 2021/09/04 20:52 It's fantastic that you are getting thoughts from

It's fantastic that you are getting thoughts from this post as
well as from our discussion made here.

# It's fantastic that you are getting thoughts from this post as well as from our discussion made here. 2021/09/04 20:53 It's fantastic that you are getting thoughts from

It's fantastic that you are getting thoughts from this post as
well as from our discussion made here.

# You can certainly see your expertise in the work you write. The world hopes for even more passionate writers like you who aren't afraid to mention how they believe. At all times go after your heart. https://parttimejobshiredin30minutes.wildapricot.org/ pa 2021/10/22 19:50 You can certainly see your expertise in the work y

You can certainly see your expertise in the work you write.
The world hopes for even more passionate writers like you
who aren't afraid to mention how they believe.
At all times go after your heart. https://parttimejobshiredin30minutes.wildapricot.org/ part
time jobs hired in 30 minutes

# If some one wants expert view regarding running a blog afterward i recommend him/her to visit this webpage, Keep up the pleasant job. 2021/10/26 2:02 If some one wants expert view regarding running a

If some one wants expert view regarding running a blog
afterward i recommend him/her to visit this webpage, Keep up
the pleasant job.

# If some one wants expert view regarding running a blog afterward i recommend him/her to visit this webpage, Keep up the pleasant job. 2021/10/26 2:03 If some one wants expert view regarding running a

If some one wants expert view regarding running a blog
afterward i recommend him/her to visit this webpage, Keep up
the pleasant job.

# If some one wants expert view regarding running a blog afterward i recommend him/her to visit this webpage, Keep up the pleasant job. 2021/10/26 2:04 If some one wants expert view regarding running a

If some one wants expert view regarding running a blog
afterward i recommend him/her to visit this webpage, Keep up
the pleasant job.

# If some one wants expert view regarding running a blog afterward i recommend him/her to visit this webpage, Keep up the pleasant job. 2021/10/26 2:05 If some one wants expert view regarding running a

If some one wants expert view regarding running a blog
afterward i recommend him/her to visit this webpage, Keep up
the pleasant job.

# What's up, all is going sound here and ofcourse every one is sharing information, that's actually excellent, keep up writing. 2021/11/12 9:06 What's up, all is going sound here and ofcourse ev

What's up, all is going sound here and ofcourse every
one is sharing information, that's actually excellent, keep up writing.

# Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why waste your intelligence on just posting videos to your weblog when you could be giving us som 2021/11/15 1:03 Write more, thats all I have to say. Literally, it

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your
point. You obviously know what youre talking about,
why waste your intelligence on just posting
videos to your weblog when you could be giving us something
enlightening to read?

# It's very effortless to find out any topic on web as compared to textbooks, as I found this paragraph at this web page. 2021/11/20 22:12 It's very effortless to find out any topic on web

It's very effortless to find out any topic on web as compared
to textbooks, as I found this paragraph at this web page.

# It's very effortless to find out any topic on web as compared to textbooks, as I found this paragraph at this web page. 2021/11/20 22:13 It's very effortless to find out any topic on web

It's very effortless to find out any topic on web as compared
to textbooks, as I found this paragraph at this web page.

# It's very effortless to find out any topic on web as compared to textbooks, as I found this paragraph at this web page. 2021/11/20 22:14 It's very effortless to find out any topic on web

It's very effortless to find out any topic on web as compared
to textbooks, as I found this paragraph at this web page.

# It's very effortless to find out any topic on web as compared to textbooks, as I found this paragraph at this web page. 2021/11/20 22:15 It's very effortless to find out any topic on web

It's very effortless to find out any topic on web as compared
to textbooks, as I found this paragraph at this web page.

# I used to be able to find good info from your content. 2021/12/17 15:55 I used to be able to find good info from your cont

I used to be able to find good info from your content.

# Hi there, I enjoy reading through your article post. I like to write a little comment to support you. 2022/01/01 13:04 Hi there, I enjoy reading through your article pos

Hi there, I enjoy reading through your article post. I like to
write a little comment to support you.

タイトル
名前
URL
コメント