[
板情報
|
カテゴリランキング
]
したらばTOP
■掲示板に戻る■
全部
1-100
最新50
|
メール
|
1-
101-
201-
301-
401-
501-
601-
701-
801-
901-
1001-
1101-
1201-
1301-
1401-
1501-
1601-
1701-
1801-
1901-
2001-
2101-
2201-
2301-
2401-
2501-
2601-
2701-
2801-
2901-
3001-
3101-
3201-
3301-
3401-
3501-
3601-
3701-
3801-
3901-
4001-
4101-
4201-
4301-
4401-
4501-
4601-
4701-
4801-
4901-
5001-
5101-
5201-
5301-
5401-
この機能を使うにはJavaScriptを有効にしてください
|
管理人の独り言(プログラミング関連)
960
:
774さん
:2008/12/02(火) 19:51:32 ID:CENbthlg0
sarファイルを処理するプログラムを書いていたんだけれども、面倒になった。やめる。
#define STRICT 1
#include <iostream>
#include <fstream>
#include <functional>
#include <algorithm>
#include <iterator>
#include <string>
#include <valarray>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <tchar.h>
#include <windows.h>
unsigned long long int _clock(){
__asm{
rdtsc
}
}
typedef unsigned int uint;
class SarManager{
protected:
std::ifstream file;
public:
SarManager(const char *filename)
: file(filename, std::ios::binary | std::ios::in)
{
if(file.fail()) throw 9999;
}
void
Write(const char *path){
if(IsEOF()) throw 1;
std::ofstream ofile(path, std::ios::binary | std::ios::out);
uint size = 0;
{
char b;
while(file.read(&b, sizeof(b) / sizeof(char)), !IsEOF() && '0' <= b && b <= '9') size = size * 10 + b - '0';
if(b != 0x0A){
throw 2;
}
}
if(size == 0){
throw 3;
}
{
char *p = new char[size];
char b;
file.read(p, size);
file.read(&b, sizeof(b) / sizeof(char));
if(b != 0x0A){
throw 4;
}
ofile.write(p, size);
delete [] p;
}
}
bool
IsEOF(){
return file.eof();
}
};
int main(int argc, char **argv){
if(argc < 2) return -1;
try{
SarManager sm(argv[1]);
int i = 0;
while(!sm.IsEOF()){
char str[1024];
sprintf(str, "%05d", i);
sm.Write(str);
i++;
}
}catch(int e){
if(e == 9999){
std::cerr << "ファイルが見つかりません><" << std::endl;
}
std::cerr << "Error : NO." << e << std::endl;
return -2;
}catch(...){
std::cerr << "Error" << std::endl;
return -3;
}
return 0;
}
新着レスの表示
名前:
E-mail
(省略可)
:
※書き込む際の注意事項は
こちら
※画像アップローダーは
こちら
(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)
スマートフォン版
掲示板管理者へ連絡
無料レンタル掲示板