2008-05-23から1日間の記事一覧

stringへの入出力

C++

「#include 」が必要。 クラスを使うだけなら「#include 」だけでいいのはなんでだろう? #include <string> #include <iostream> using namespace std; int main() { string s; cin >> s; cout << s; return 0; }</iostream></string>

cin.unsetf(ios::skipws)

C++

読み込めない…なんでー? #include <iostream> using namespace std; int main() { char cs[256]; cin.unsetf(ios::skipws); cin >> cs; cout << cs << endl; return 0; } 100続行するには何かキーを押してください . . .</iostream>

ファイル入出力

C++

入力を出力につなげてみたらコンパイルできず。 できそうな感じだけど。 #include <string> #include <iostream> #include <fstream> using namespace std; int main() { string buf; ofstream fout("C:/foo.txt"); if (!fout.is_open()) { exit(1); } fout << "あいうえお"; fout.close</fstream></iostream></string>…

可変長引数

C++

C言語と同じやり方しかないのかな? #include <iostream> #include <cstdarg> using namespace std; void func(int n, ...) { va_list args; va_start(args, n); for (int i = 0; i < n; i++) { int v = va_arg(args, int); cout << v << endl; } va_end(args); } int main() { </cstdarg></iostream>…

EOFを読んだらeof() == true

C++

ふむふむ。 #include <iostream> #include <fstream> using namespace std; int main() { ofstream fout("foo.txt"); if (!fout.is_open()) { exit(1); } fout << "ABCDE"; fout.close(); ifstream fin("foo.txt"); if (!fin.is_open()) { exit(1); } fin.seekg(-1, ios::end); </fstream></iostream>…

入出力をつなげてみる

C++

#include <iostream> #define BUFSIZE 256 using namespace std; istream &operator>>(istream &in, ostream &out) { char buf[BUFSIZE]; streamsize n; do { in.read(buf, BUFSIZE); n = in.gcount(); out.write(buf, n); } while (n >= BUFSIZE); return in; } int m</iostream>…

鼻毛はアマゾンで

Googleで「鼻毛」を検索すると、スポンサーリンクに「鼻毛はアマゾンで」と出てくる。言いたいことは分かる。でもねぇ…