生活随笔
收集整理的這篇文章主要介紹了
C++:小说阅读器
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
C++:小說閱讀器
這是我自己用 C++ & 減小代碼長(zhǎng)度用的批處理 做的一個(gè)用來看小說的程序,使用批處理主要是不太會(huì)C++Web編程,請(qǐng)求大佬們指教
現(xiàn)在這里還沒加入什么小說,有什么比較好看的請(qǐng)各位推薦
文章目錄
- C++:小說閱讀器
- 說明
- 下載
- 抱歉,之前打包版出現(xiàn)了小問題,現(xiàn)已解決
- 更新日志
- 代碼
- 制作:
說明
這是用的我自己的服務(wù)器,里面的小說需要自己處理才可使用,并且程序會(huì)自動(dòng)更新,更新日志會(huì)在這里發(fā)布。
因?yàn)镃++訪問網(wǎng)絡(luò)過于麻煩,現(xiàn)在正考慮將語言換成Python
下載
抱歉,之前打包版出現(xiàn)了小問題,現(xiàn)已解決
更新日志
2020.8.21前的更新日志忘了
- 2020.8.21
添加了學(xué)生機(jī)功能
版本&版本號(hào):1.0.6-200821 8 - 2020.9.12
修改了更新的批處理,將主界面修改為管理員方式運(yùn)行
版本&版本號(hào):1.0.7-200912 9 - 2021.7.28 更換服務(wù)器
不做版本更新,因?yàn)橹暗挠蛎麩o法解析,請(qǐng)重新安裝最新版本
代碼
1. 打包版本
簡(jiǎn)化代碼,只留下更新部分
#include<bits/stdc++.h>
#include<windows.h>
#include<string>
#include<conio.h>
#define _for(i,a,b) for(int i=a;i<b;i++)
#define handle GetStdHandle(STD_OUTPUT_HANDLE)
#define EDITION_ID -1
#define EDITION 0.0.0-20190000
using namespace std
;
void cursor(bool a
){CONSOLE_CURSOR_INFO CursorInfo
;GetConsoleCursorInfo(handle
, &CursorInfo
);CursorInfo
.bVisible
= a
;SetConsoleCursorInfo(handle
, &CursorInfo
);
}
void update(){system("cls");printf("檢查更新...");system("bitsadmin /transfer 檢查更新 https://sakuyark.com/novel/api/edition %cd%\\edition.txt");ifstream
update_input("edition.txt");int editionid
;update_input
>>editionid
;if(editionid
>EDITION_ID
){system("start update");exit(0);}
}
void init(){system("mode con cols=90 lines=30");ofstream
update_code("update.bat");update_code
<<"@echo off\n"\
<<"set mycd=%cd%\n"\
<<"cd /d %~dp0\n"\
<<"%1 start \"\" mshta vbscript:createobject(\"shell.application\").shellexecute(\"\"\"%~0\"\"\",\"::\",,\"runas\",1)(window.close)&exit\n"\
<<"bitsadmin /transfer 檢查更新 https://sakuyark.com/novel/api/update_list %mycd%\\update_list.txt\n"\
<<"for /f \"delims=\" %%i in (update_list.txt) do bitsadmin /transfer 更新文件%%i http://aichistudio.space/static/file/novel/%%i %mycd%\\%%i\n"\
<<"start main.exe\n"\
<<"exit";
}
int main(){init();update();return 0;
}
2. 最新代碼
#include<bits/stdc++.h>
#include<windows.h>
#include<string>
#include<conio.h>
#define _for(i,a,b) for(int i=a;i<b;i++)
#define handle GetStdHandle(STD_OUTPUT_HANDLE)
#define EDITION_ID 9
#define EDITION 1.0.7-200912
using namespace std
;
void main_interface();
void cursor(bool a
){CONSOLE_CURSOR_INFO CursorInfo
;GetConsoleCursorInfo(handle
, &CursorInfo
);CursorInfo
.bVisible
= a
;SetConsoleCursorInfo(handle
, &CursorInfo
);
}
void update(){system("cls&del edition.txt");system("title 檢查更新...");printf("檢查更新...");system("bitsadmin /transfer 檢查更新 https://sakuyark.com/novel/api/edition %cd%\\edition.txt");ifstream
update_input("edition.txt");int editionid
;update_input
>>editionid
;if(editionid
>EDITION_ID
){system("start update");exit(0);}
}
void local_novels(){system("cls&title 本地小說");system("dir %cd%\\novels\\* /B > list.txt");char novels
[500][200]={};int n
=0;ifstream
local_novel_list("list.txt");while(local_novel_list
.getline(novels
[n
++],200));if(strlen(novels
[0])==0){printf("沒有小說");system("pause");return;}n
--;W
:system("cls");printf("輸入0來返回\n");_for(i
,0,n
){printf("%d. %s\n",i
+1,novels
[i
]);}printf("id: ");int k
=0;scanf("%d",&k
);if(k
==0)return;if(k
>0&&k
<=n
){freopen("novel.txt","w",stdout);printf(novels
[k
-1]);system("start novel.exe");exit(0);}else{printf("id錯(cuò)誤!");Sleep(2000);goto W
;}
}
void download_novels(){system("cls");system("title 獲取小說列表...");system("bitsadmin /transfer 獲取小說列表 https://sakuyark.com/novel/api/list %cd%\\weblist.txt");char novels
[500][200]={};int n
=0;ifstream
local_novel_list("weblist.txt");while(local_novel_list
.getline(novels
[n
++],200));n
--;W
:system("cls&title 下載新小說");_for(i
,0,n
){printf("%d. %s\n",i
+1,novels
[i
]);}printf("id: ");int k
=0;scanf("%d",&k
);if(k
>0&&k
<=n
){string download_code
="download ";download_code
.append(novels
[k
-1]);system(download_code
.data());return;}else{printf("id錯(cuò)誤!");Sleep(2000);goto W
; }
}
void main_interface(){R
: system("cls&title 主界面");printf("1.本地小說 2.下載新的");W
: char k
=getch();if(k
=='1')local_novels();else if(k
=='2')download_novels();else goto W
;goto R
;
}
void init(){system("mode con cols=90 lines=30");cursor(0);system("md novels");ofstream
update_code("update.bat");update_code
<<"@echo off\n"\
<<"set mycd=%cd%\n"\
<<"cd /d %~dp0\n"\
<<"%1 start \"\" mshta vbscript:createobject(\"shell.application\").shellexecute(\"\"\"%~0\"\"\",\"::\",,\"runas\",1)(window.close)&exit\n"\
<<"bitsadmin /transfer 檢查更新 https://sakuyark.com/novel/api/update_list %mycd%\\update_list.txt\n"\
<<"for /f \"delims=\" %%i in (update_list.txt) do bitsadmin /transfer 更新文件%%i https://sakuyark.com/static/file/novel/%%i %mycd%\\%%i\n"\
<<"start main.exe\n"\
<<"exit";ofstream
download_code("download.bat");download_code
<<"bitsadmin /transfer 下載《%1》 https://sakuyark.com/static/file/novel/%1.txt %cd%\\novels\\%1";
}
VOID
ManagerRun(LPCSTR exe
,LPCSTR param
,INT nShow
=SW_SHOW
){SHELLEXECUTEINFO ShExecInfo
; ShExecInfo
.cbSize
= sizeof(SHELLEXECUTEINFO
); ShExecInfo
.fMask
= SEE_MASK_NOCLOSEPROCESS
; ShExecInfo
.hwnd
= NULL; ShExecInfo
.lpVerb
= "runas"; ShExecInfo
.lpFile
= exe
; ShExecInfo
.lpParameters
= param
; ShExecInfo
.lpDirectory
= NULL; ShExecInfo
.nShow
= nShow
; ShExecInfo
.hInstApp
= NULL; BOOL ret
= ShellExecuteEx(&ShExecInfo
); CloseHandle(ShExecInfo
.hProcess
);return;
}
int main(int argc
,char *argv
[]){if(argc
==1){ShowWindow(GetConsoleWindow(),SW_HIDE
);ManagerRun(argv
[0],"2");return 1;}else if(argc
==2){init();update();main_interface();}return 0;
}
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#define _for(i,a,b) for(int i=a;i<b;i++)
#define handle GetStdHandle(STD_OUTPUT_HANDLE)
using namespace std
;
char name
[500];
int id
,line
,n
;
bool SCM
;
string novels
[100000];
ifstream novel
;
HWND hWnd
=GetForegroundWindow();
void gotoxy(double x
,int y
){COORD pos
;pos
.X
=2*x
;pos
.Y
=y
;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE
),pos
);
}
void cursor(bool a
){CONSOLE_CURSOR_INFO CursorInfo
;GetConsoleCursorInfo(handle
, &CursorInfo
);CursorInfo
.bVisible
= a
;SetConsoleCursorInfo(handle
, &CursorInfo
);
}
void init(){system("mode con cols=90 lines=9999");cursor(0);
}
void input(){{ifstream
tttt("novel.txt");tttt
>>name
;}{ifstream
temp(name
);temp
>>id
;}string code
="novels/";code
.append(name
);novel
.open(code
.data());_for(i
,0,id
+1){getline(novel
,novels
[i
],'|');}n
=id
;string title_code
="title ";title_code
.append(name
);title_code
.append("(按下 Q 啟動(dòng)學(xué)生機(jī)模式)");system(title_code
.data());
}
void keep(){ofstream
keeping(name
);keeping
<<id
;
}
void read(){W
: system("cls");cout
<<novels
[id
];gotoxy(0,0);line
=0;while(1){cursor(0);if(_kbhit()){char k
=_getch();if(k
==72||k
=='w'||k
=='W'){if(line
>=5){line
-=5;gotoxy(0,line
);}}if(k
==80||k
=='s'||k
=='S'){line
+=5;gotoxy(0,line
);}if(k
==75||k
=='a'||k
=='A'){if(id
>0){id
--;keep();goto W
;}}if(k
==77||k
=='d'||k
=='D'){id
++;if(id
>n
){n
=id
;getline(novel
,novels
[id
],'|');}keep();goto W
;}if(k
=='q'||k
=='Q'){if(!SCM
){string title_code
="title ";title_code
.append(name
);title_code
.append("_學(xué)生機(jī)模式(按下Q來關(guān)閉)");system(title_code
.data());}else{string title_code
="title ";title_code
.append(name
);title_code
.append("(按下 Q 啟動(dòng)學(xué)生機(jī)模式)");system(title_code
.data());SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
); }SCM
=!SCM
;}}if(SCM
)SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);if(!SCM
)Sleep(10);}
}
int main(){init();input();read();return 0;
}
制作:
From Sakuyark,
網(wǎng)站:https://sakuyark.com
QQ交流群:1032103456
總結(jié)
以上是生活随笔為你收集整理的C++:小说阅读器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。