Skip to content

Instantly share code, notes, and snippets.

@LilinYume
Created February 11, 2014 12:13
Show Gist options
  • Save LilinYume/8933726 to your computer and use it in GitHub Desktop.
Save LilinYume/8933726 to your computer and use it in GitHub Desktop.
/*
* main.cpp
*
* Created on: 2014/02/11
* Author: Resorcin
*/
#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
using namespace std;
const int InputLimit = 10;
struct stamp
{
private:
time_t time_val;
struct tm *look_into;
int yy, mm, dd;
public:
// 日付の取得
stamp()
{
time_val = time( NULL );
look_into = localtime( &time_val );
yy = look_into-> tm_year;
mm = look_into-> tm_mon;
dd = look_into-> tm_mday;
}
// スタンプする日付を渡す
void express( int &year, int &month, int &day )
{
const int year_diff = 1900;
const int mon_diff = 1;
yy += year_diff;
mm += mon_diff;
year = yy;
month = mm;
day = dd;
}
};
class FileOut
{
private:
int cost;
int size;
int cost_list[InputLimit];
ofstream fsOut;
char* ToChar_slice_digit();
public:
FileOut()
{
cost = 0;
size = 0;
for( int i = 0; i < InputLimit; ++i ) cost_list[i] = 0;
fsOut.open("D:\\tmp.txt", ios::out | ios::binary);
}
~FileOut()
{
fsOut.close();
}
void Data_input();
void Write();
};
// 整数値の入力Promt
void FileOut::Data_input()
{
int index = 0;
cout << "Type any char to end\n";
// シンボル定数(10)回 または正の整数値以外の入力で終了
while( index < InputLimit )
{
cout << "Input Cost: ";
cin >> cost;
// failbitフラグがあればクリアしてループを抜ける
if( cost < 0 || cin.fail() )
{
cout << "Terminated your Input";
size = index;
cin.clear();
break;
}
else
{
cost_list[index] = cost;
++index;
}
// 入力された回数をメンバ変数に保持
size = index;
}
}
// 整数値の各桁をcharの配列に変換
char* FileOut::ToChar_slice_digit()
{
int mod, num;
vector<int> digit;
mod = num = 0;
if( !size ) return 0; // 何も入力がない場合
for( int i = 0; i <= size; ++i )
{
num = cost_list[i];
for( int j = 0; 1 <= cost_list[i]; ++j )
{
mod = num % 10;
num = num / 10;
digit.push_back( mod );
}
}
// charのポインタ へキャスト
for( int i = 0; i < digit.size(); ++i)
reinterpret_cast<char *>(digit[i]);
return digit;
}
int main()
{
FileOut out_proc;
out_proc.Data_input();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment