Skip to content

Commit

Permalink
20180419.2325
Browse files Browse the repository at this point in the history
  • Loading branch information
flagoop committed Apr 19, 2018
1 parent 3475992 commit 58c7d7f
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 0 deletions.
Binary file modified ConsoleApplication2/ConsoleApplication2/ConsoleApplication2.cpp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<ItemGroup>
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="test.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ConsoleApplication2.cpp" />
Expand All @@ -158,6 +159,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="test.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ClInclude Include="targetver.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="test.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand All @@ -29,5 +32,8 @@
<ClCompile Include="ConsoleApplication2.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="test.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions ConsoleApplication2/ConsoleApplication2/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
skfj,jewriu!jj lk;over&&like jjso oqpz,OK!
Binary file modified ConsoleApplication2/ConsoleApplication2/stdafx.h
Binary file not shown.
1 change: 1 addition & 0 deletions ConsoleApplication2/ConsoleApplication2/temperture_rec.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions ConsoleApplication2/ConsoleApplication2/temperture_rec2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{year 2000{month jan (1 0 -20.5166 ) (1 1 28.4506 )}}
{year 2001{month jan (1 0 33.5166 ) (1 1 6.4506 )}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{year 2000{month jan (1 0 -20.5166 ) (1 1 28.4506 )}}
{year 2001{month jan (1 0 33.5166 ) (1 1 6.4506 )}}
221 changes: 221 additions & 0 deletions ConsoleApplication2/ConsoleApplication2/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
#include "stdafx.h"
#include "test.h"


void binaryfile_to_binaryfile(ifstream &ifs,ofstream &ofs)
{
//ifstream ifs("tt.jpg", ios::binary | ios::ate);
//ofstream ofs("tt_bak.jpg", ios::binary);
char *memblock = nullptr;
if (ifs)
{
auto filesize = ifs.tellg();
memblock = new char[filesize];
ifs.seekg(0, ios::beg);
ifs.read(memblock, filesize);
ofs.write(memblock, filesize);

//cout << memblock << endl; //binary 不可以输出。。。
cout << "file size:" << filesize << " bytes >file copy succesed.\n";
delete[] memblock;
ifs.close();
ofs.close();
}
else
{
cerr << "open origin file is invaild.\n";
}
}

void End_of_loop(istream &is,const char c,const string &s)
{
char ch;
is >> ch;
if (ch != c)
{
throw Input_type_error(s);
}

}

int month_to_int(const string &mm)
{
if (mm == "jan") return 1;
if (mm == "feb") return 2;
if (mm == "mar") return 3;
if (mm == "apr") return 4;
if (mm == "may") return 5;
if (mm == "jun") return 6;
if (mm == "jul") return 7;
if (mm == "aug") return 8;
if (mm == "sep") return 9;
if (mm == "oct") return 10;
if (mm == "nov") return 11;
if (mm == "dec") return 12;
return 0;
}

void Input_error(const string &s)
{
throw Input_type_error(s);

}

void FileReadingTest::read_file()
{
int line = 1;
Reading rd;
while (true)
{
ist >> rd.uHour >> rd.dTemperature;
if (ist.eof())
{
cout << "Reading file sucessed. End of file.\n";
break;
}
if (chkfile())
vecReading.push_back(rd);
else
{
cout << "line " << line << " data is invalid.\n";
break;
}
++line;

}
}

void FileReadingTest::pt_file()
{
read_file();
cout << "File context:\n";
for (auto c : vecReading)
{
cout << "hour:" << c.uHour << " Temperature:" << c.dTemperature << endl;

}
}

bool FileReadingTest::chkfile()
{
if (ist.fail() || ist.bad())
{
cout << "bad reading in file.\n";
//funerr("bad reading in file.");
return false;
}
return true;
}

istream & operator>>(istream & is, Reading2 & r)
{
// TODO: 在此处插入 return 语句
char ch1;
if (is>>ch1 && ch1!='(')
{
is.unget();
is.clear(ios_base::failbit);
return is;
}

char ch2;
int d;
int h;
double t;
is >> d >> h >> t >> ch2;
//if (!is || ch2 != ')') funerr("bad reading.");
if (!is || ch2 != ')') cerr << "bad reading.\n";

r.day = d;
r.hour = h;
r.tmps = t;
return is;


/*
for (char ch;is>>ch;)
{
if (ch=='(')
{
is >> r.day >> r.hour >> r.tmps;
if (!is || ch)
{
}
return is;
}
}
return is;
*/
}

istream & operator>>(istream & is, Month & m)
{
char ch;
is >> ch;
if (ch!='{')
{
is.unget();
is.clear(ios_base::failbit);
return is;
}

string month_marker;
string str_month;
is >> month_marker>>str_month;
if (!is || month_marker!="month")
{
Input_type_error("bad month marker.");
}
m.month = month_to_int(str_month);
for (Reading2 r;is>>r;)
{
m.vec_day[r.day].vec_hour[r.hour] = r.tmps;
}
End_of_loop(is, '}', "bad end of month");
return is;
}

istream & operator>>(istream & is, Year & y)
{
// TODO: 在此处插入 return 语句
char ch;
is >> ch;
if (ch!='{')
{
is.unget();
is.clear(ios_base::failbit);
//Input_error("file struct is invaild.");
}


string str_year;
int yy;
is >> str_year >> yy;
if (!is || str_year!="year")
{
throw Input_type_error("data struct is invaild.");
}
y.year = yy;

while (true)
{
Month m;
if (!(is >> m))break;
//todo
y.vec_month[m.month] = m;
}

End_of_loop(is, '}', "bad end of year.");

return is;
}

GetWord & GetWord::operator>>(vector<string>& v)
{
// TODO: 在此处插入 return 语句



return *this;
}
94 changes: 94 additions & 0 deletions ConsoleApplication2/ConsoleApplication2/test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#pragma once
#include "stdafx.h"

class GetWord
{
public:
GetWord(ifstream &ifs, string &wch) :ifs(ifs), white_ch(wch) {};
void add_white_char(const string &s) { white_ch += s; }
GetWord& operator>>(vector<string> &v);
protected:
private:
ifstream &ifs;
string white_ch;
istringstream buffer;
};

void binaryfile_to_binaryfile(ifstream &ifs, ofstream &ofs);

void Input_error(const string &s);
void End_of_loop(istream &is, const char c, const string &s);
int month_to_int(const string &mm);

class Input_type_error
{
public:
Input_type_error(string s) :msg(s) {}
string msg;
};

const int not_a_reading = -900;
const int not_a_month = -1;

struct Day
{
vector<double> vec_hour{ vector<double>(24,not_a_reading) };
};

struct Month
{
int month{ not_a_month };
vector<Day> vec_day{ 31 };
};

struct Year
{
int year;
vector<Month> vec_month{ 12 };
};

struct Reading2
{
size_t day;
size_t hour;
double tmps;
};

class Date
{
public:
protected:
private:
size_t year;
size_t month;
size_t day;
};

enum class Month_enum
{
jan=1,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
};

istream& operator>>(istream &is, Reading2 &r);
istream& operator>>(istream &is, Month &m);
istream& operator>>(istream &is, Year &y);


class FileReadingTest
{
public:
FileReadingTest(const string &fname) :ist(fname) {}
void read_file();
void pt_file();
protected:
private:
struct Reading
{
unsigned uHour;
double dTemperature;
};
vector<Reading> vecReading;
ifstream ist;

bool chkfile();
};
Binary file added ConsoleApplication2/ConsoleApplication2/tt.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

0 comments on commit 58c7d7f

Please sign in to comment.