今回は初心者向けでアバウトな講座です。
今回の講座で
- C/C++言語非常に簡単に使うことができるようになれます。
- C/C++での基本的な書き方が学べます。
- char型の扱い方が学べます。
chara.hpp
# include <string>
class ZipStream
{
public:
ZipStream(int val);
ZipStream(std::string val);
ZipStream(std::string val, bool zipped);
~ZipStream();
ZipStream Zipped();
ZipStream UnZipped();
ZipStream operator+(ZipStream Z);
ZipStream operator+=(ZipStream Z);
inline std::string Get_Value() {
return this->values;
}
private:
std::string values;
bool now_zip;
inline char Reter(int Oh) {
return (char)Oh;
}
inline int Purse(char t) {
return t & 0xff;
}
};
chara.cpp
# include"chara.hpp"
# include <array>
# include <sstream>
using sstr = std::stringstream;
ZipStream::ZipStream(int val)
:values(std::to_string(val))
,now_zip(false)
{
}
ZipStream::ZipStream(std::string val)
:values(val)
,now_zip(false)
{
}
ZipStream::ZipStream(std::string val, bool zipped)
: values(val)
,now_zip(zipped)
{
}
ZipStream ZipStream::operator+(ZipStream Z){
if((Z.now_zip ^ this->now_zip) == false){
ZipStream V(this->values + '\n' + Z.values,this->now_zip);
return V;
}
else{
return *this;
}
}
ZipStream ZipStream::operator+=(ZipStream Z){
if((Z.now_zip ^ this->now_zip) == false){
this->values = this->values + '\n' + Z.values;
}
return *this;
}
ZipStream::~ZipStream()
{
}
ZipStream ZipStream::Zipped ()
{
if (this->now_zip)
{
return *this;
}
sstr ss;
for (auto l : this->values)
{
ss << std::hex << Purse(l) <<",";
}
this->values = ss.str();
this->now_zip = true;
return *this;
}
ZipStream ZipStream::UnZipped() {
if (!this->now_zip)
{
return *this;
}
std::string ok, ret;
int k;
for (auto st : this->values)
{
if (st == ',') {
std::istringstream(ok) >> std::hex >> k;
ret += Reter(k);
ok = "";
}
else
{
ok += st;
}
}
this->values = ret.c_str();
this->now_zip = false;
return *this;
}
AbeOut.cpp
# include<iostream>
# include"chara.hpp"
using std::cout;
void AbeOut(int num) {
ZipStream Z("e5,ae,89,e5,80,8d,e3,81,af,e8,be,9e,e3,82,81,e3,82,8d,", true);
if (num>0)
{
cout << Z.UnZipped().Get_Value() << std::to_string(num) << std::endl;
}
else
{
cout << Z.UnZipped().Get_Value() << std::endl;
}
}
int main(void) {
AbeOut(210);
AbeOut(0);
}
ターミナル
>>> cl /EHsc About.cpp chara.cpp
問題
- AbeOut(210)の答えを述べよ
- AbeOut(0)の答えを述べよ