2006-11-01から1ヶ月間の記事一覧

複数のファイルにあるデータをもとに文を作るプログラム

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> /*定数の定義*/ #define WORDMAX 500 /*単語の最大数*/ #define BUFLEN 256 /*1行の最大バイト数*/ void getWord(char *fileName, char *buf) { char tmpStr[BUFLEN]; int count = 0, selected; long wordLocation[</time.h></string.h></stdlib.h></stdio.h>…

fread/fwrite関数

#include <stdio.h> #include <stdlib.h> #define MAX 10 /*データの個数*/ #define OUTFILE "result3.txt" /*出力ファイル名*/ int main() { int i, data[MAX]; FILE *outStream; /*データの作成*/ for(i = 0; i < MAX; i++) data[i] = i * i; /*出力用ファイルのオープン*/ if</stdlib.h></stdio.h>…

fprintf/fscanf関数

#include <stdio.h> #include <stdlib.h> #define INFILE "data2.txt" /*入力フィル名*/ #define OUTFILE "result2.txt" /*出力ファイル名*/ int main() { int data, sum = 0, num = 0; double avr; FILE *inStream, *outStream; /*入力用ファイルのオープン*/ if((inStream = f</stdlib.h></stdio.h>…

fgetc/fputc関数

#include <stdio.h> #include <stdlib.h> #include <ctype.h> #define INFILE "data1.txt" /*入力ファイル名*/ #define OUTFILE "result1.txt" /*出力ファイル名*/ int main() { int c, d; FILE *inStream, *outStream; /*入力用ファイルのオープン*/ if((inStream = fopen(INFILE, "r"))</ctype.h></stdlib.h></stdio.h>…

fopen関数の第2引数(mode)に指定する文字列

引数 概要 "r" 読み込み "w" 書き込み "a" 追加 "r+" 更新(既存のファイルを読み書きできるように開く) "w+" 更新(既存ファイルの内容は消去される) "a+" 更新(更新用に開き、その末尾に書く)

単方向リスト

#include <stdio.h> #include <stdlib.h> /*構造体の定義*/ struct node { int num; struct node *next; }; typedef struct node NODE; NODE *start = NULL; /*リストにデータを追加する関数(並べ替えつき)*/ void addList(int data) { NODE *p = start, *pend = NULL, *new; /*</stdlib.h></stdio.h>…

HugeDomains.com - Shop for over 300,000 Premium Domains

http://www.workmethod.com/

setコンテナで名前から電話番号を検索する例

#include <iostream> #include <string> #include <set> using namespace std; class CAddress { public: string m_strName; string m_strTel; CAddress(){} CAddress(const string& name, const string& tel) {m_strName = name; m_strTel = tel;} }; bool operator<(const CAddres</set></string></iostream>…

mapコンテナで名前から電話番号を検索する例

#include <iostream> #include <string> #include <map> using namespace std; int main() { map<string, string> mapAdrs; mapAdrs.insert(pair<string, string>("Anne", "1111-1111")); mapAdrs.insert(pair<string, string>("Charlie", "3333-3333")); mapAdrs.insert(pair<string, string>("Bob", "2222-2222")); mapAd…</string,></string,></string,></string,></map></string></iostream>

listコンテナを使った例

#include <stdio.h> #include <list> using namespace std; int main() { list<int> lst; list<int>::iterator p; int i; for(i = 1; i < 6; i++) lst.push_back(i); for(p = lst.begin(); p != lst.end(); p++) printf("%d ", *p); putchar('\n'); for(i = 1; i < 6; i++) lst.push_f</int></int></list></stdio.h>…

STLの反復子の種類

種類 サポートする演算子 ランダム・アクセス反復子 ->, *, =, +, -, ++, -, [], , =, +=, -=, ==, != 双方向反復子 ->, *, =, ++, -- 前方反復子 ->, *, =. ++, ==, != 入力反復子 ->, *, =, ++, ==, != 出力反復子 =, *, ++

反復子を使ってコンテナにアクセスする

#include <stdio.h> #include <vector> using namespace std; int main() { vector<int> vec(10); vector<int>::iterator p; p = vec.begin(); int i = 0; while(p != vec.end()){ *p++ = i++; } int sum = 0; for(p = vec.begin(); p != vec.end(); p++){ sum += *p; } printf("0+1+2+.</int></int></vector></stdio.h>…

vectorに要素を追加するコードと実行結果

#include <stdio.h> #include <vector> using namespace std; int main() { vector<int> vec; printf("size = %d, capacity = %d\n", vec.size(), vec.capacity()); for(int i = 0; i < 10; i++){ vec.push_back(i); } printf("size = %d, capacity = %d\n", vec.size(), vec.capac</int></vector></stdio.h>…

vectorコンテナを利用する例

#include <stdio.h> #include <vector> using namespace std; int main() { vector<int> vec(10); int i; for(i = 0; i < 10; i++){ vec[i] = i; } int sum = 0; for(i = 0; i < 10; i++){ sum += vec[i]; } printf("0+1+2....+9 = %d\n", sum); return 0; }</int></vector></stdio.h>

それぞれのデータ操作に対するコンテナの処理速度

コンテナの種類 先頭へ要素を追加/削除 末尾に要素を追加/削除 コンテナの途中に要素を追加/削除 ランダム・アクセス 検索 vector O(N)+ O(1)+ O(N)+ O(1) O(N) deque O(1)+ O(1) O(N) O(1) O(N) list O(1) O(1) O(1) × O(N) map O(logN) O(logN) O(logN) × O…

STLが提供するコンテナ

コンテナの種類 特徴 vector 動的配列。ランダム・アクセスが可能で末尾への挿入/削除が高速 deque 両端キュー。ランダム・アクセスが可能で先頭と末尾への挿入/削除が高速 list 双方向リスト map キーに対応する値を高速に検索できる。キーの重複を許さない …

クラステンプレートと利用例

#include <stdio.h> const double PI = 3.14159; template<class TYPE> class CCircle { public: TYPE x; TYPE y; TYPE r; CCircle(){} CCircle(TYPE X, TYPE Y, TYPE R){x = X; y = Y; r = R;} TYPE CalcArea(){return r * r * PI;} void Move(TYPE, TYPE); }; template <class TYPE> void CC</class></class></stdio.h>…

テンプレート関数でクラスを引数にもできる

#include <stdio.h> #include <string.h> class CPerson { public: char* m_pszName; //名前 int m_nAge; //年齢 CPerson(char*, int); CPerson(){m_pszName = NULL; m_nAge = 0;} ~CPerson(){if(m_pszName) delete[] m_pszName;} CPerson(CPerson&); CPerson& operator=(CPerso</string.h></stdio.h>…

挿入ソートをテンプレートにしたもの

#include <stdio.h> template<class TYPE> void Sort(TYPE a[], int n) { int i, j; for(i = 1; i < n; i++){ j = i; while(j > 0 && a[j] < a[j-1]){ Swap(a[j], a[j-1]); j--; } } } template<class TYPE> void Swap(TYPE& a, TYPE& b) { TYPE tmp = a; a = b; b = tmp; } int main() { int </class></class></stdio.h>…

普通の関数とテンプレートの関数の呼び出しの優先順位を調べるテスト

#include <stdio.h> void Func(float f1, float f2) { printf("普通の関数が呼ばれました\n"); } template<class TYPE> void Func(TYPE f1, TYPE f2) { printf("テンプレート関数が呼ばれました\n"); } int main() { Func(5.5f, 7.5f); Func(5, 7); Func(5.5f, 7); Func<int>(5.5f, 7);</int></class></stdio.h>…

関数テンプレート

#include <stdio.h> template<class TYPE> void Swap(TYPE& a, TYPE& b) { TYPE tmp = a; a = b; b = tmp; } int main() { int n1 = 5, n2 = 7; Swap(n1, n2); printf("交換後:(n2, ,2) = (%d, %d)\n", n1, n2); float f1 = 5.5, f2 = 7.5; Swap(f1, f2); printf("交換後:(f1, f</class></stdio.h>…

Effective C++ 原著第3版 (ADDISON-WESLEY PROFESSIONAL COMPUTING SERIES)

Effective C++ 原著第3版 (ADDISON-WESLEY PROFESSIONAL COMPUTING SERIES)作者: スコット・メイヤーズ,小林健一郎出版社/メーカー: ピアソン・エデュケーション発売日: 2006/04/29メディア: 大型本購入: 29人 クリック: 411回この商品を含むブログ (186件) …

構文解析とは?

構文解析とは、トークンをいくつか集めて、指定された順番に並んでいるかをチェックする処理である。しかし、一般の言語 (プログラミング言語や、自然言語など)は、ただその順番を規定するだけではその構造を規定する(文法という)ことはできない。その文法を…

字句解析とは?

字句解析とは、コンパイラの中で最初に処理する部分である。そのため、 `生'のプログラム(ユーザが書いたプログラム、ソースプログラムという) を入力とする。例えば、C言語のソースプログラム、 main() { printf( "hello world!\n" ); } に対して、main、(…

代入演算子とコピー・コンストラクタを明示的に定義する

#include <iostream.h> #include <string.h> class CBook { char* ptitle; int price; public: CBook(const CBook&); CBook(const char* , int); ~CBook(){delete[] ptitle;} const char* get_title(){return ptitle;} CBook& operator=(const CBook&); }; CBook& CBook::operator=</string.h></iostream.h>…

デフォルトの代入演算子を使用時の問題

#include <iostream.h> #include <string.h> class CBook { char* ptitle; int price; public: CBook(const char* , int); ~CBook(){delete[] ptitle;} const char* get_title(){return ptitle;} }; CBook::CBook(const char* ptitle_, int price_) : price(price_) { ptitle = new</string.h></iostream.h>…

データ・メンバーを宣言する順序に問題がある

#include <iostream> #include <string> using namespace std; class CEmployee { int salary; int age; string name; public: CEmployee(const string&, int); int get_salary(){return salary;} const string get_name(){return name;} }; CEmployee::CEmployee(const string</string></iostream>…

コンストラクタとデストラクタが呼び出されるタイミングを調べるプログラム

#include <iostream> using namespace std; class CFoo { int num; public: CFoo(int n):num(n) {cout << "コンストラクタが呼ばれました:" << num << '\n';} ~CFoo() {cout << "デストラクタが呼ばれました :" << num << '\n';} }; int main() { CFoo foo1(1); CFoo</iostream>…

takagi.in - 高木信尚ホームページ

http://takagi.in/index.php

Microsoft API and Reference Catalog

MSDNのドキュメント「MBCSのプログラミングについて」