0
已解决
李承耀
新手光能
新手光能
新团队:LOS官方团队 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include<bits/stdc++.h>
#include<windows.h>
#define clear_cin() fflush(stdin)
using namespace std;
string s,t;
void clear(){
system("cls");
clear_cin();
}
void ert(){
MessageBeep(MB_ICONERROR);
}
void output(){
cout<<"小小记事本1.1\n";
cout<<"编译日期:2022/12/26\n";
cout<<"按Ctrl+Z停止输入\n";
while(getline(cin,t)){
s+=t+'\n';
}
cin.clear();
cout<<"\n文件目录:";
string a;
getline(cin,a);
cout<<"\n文件名(加后缀名):";
string r;
getline(cin,r);
a+=r;
//cout<<"文件名+目录:"<<a;
FILE* fp=fopen(a.c_str(),"w");
fprintf(fp,s.c_str());
fclose(fp);
cout<<"写入完成!\n按Enter继续";
getchar();
}
void input(){
cout<<"小小记事本1.1\n";
cout<<"编译日期:2022/12/26\n";
cout<<"输入地址和文件名(带后缀)";
string s;
getline(cin,s);
ifstream fin(s.c_str());
string t;
bool flag=0;
while(getline(fin,t)){
cout<<t<<endl;
flag=1;
}
if(!flag)cout<<"文件为空或无该文件\n";
cout<<"按Enter继续";
getchar();
}
int main(){
system("title 小小记事本1.1 Build 1100");
while(1){
clear();
cout<<"小小记事本1.1\n";
cout<<"编译日期:2022/12/26\n";
cout<<"1.写入文件\n2.读取文件\n3.版本号\n4.退出\n";
string s;
getline(cin,s);
clear();
if(s=="1"||s=="1.写入文件"||s=="写入文件"){
output();
}
else if(s=="2"||s=="2.读入文件"||s=="读入文件"){
input();
}
else if(s=="3"||s=="3.版本号"||s=="版本号"){
cout<<"小小记事本1.1 Build 1100\n";
cout<<"编译日期:2022/12/26\n";
cout<<"按Enter继续";
getchar();
}
else if(s=="4"||s=="4.退出"||s=="退出")break;
else{
ert();
}
}
return 0;
}
0
已采纳
沙宸安
高级启示者
高级启示者
我认为可以使用如下代码修改窗口的标题,这样可以保证在显示的时候不会有“**员:”前缀
void console()
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO bInfo;
GetConsoleScreenBufferInfo(hOut, &bInfo );
SetConsoleTitle("XACRAFT 3.3 简体中文版"); // 设置窗口的标题
}
还有不知道为什么在我的电脑上无法停止输入
0
0
薛乘志
初级启示者
初级启示者
0
0
0
包涵宇
中级天翼
中级天翼
#include<bits/stdc++.h>
#include<iostream>
#include <fstream>
#include <string>
#include<time.h>
#include<windows.h>
#include<conio.h>
#include<cstdio>
#define get(VK_NONAME) (GetAsyncKeyState(VK_NONAME))
#define clean (system("cls"))
#define sl(x) (Sleep(x))
using namespace std;
FILE *pFile;
string ta;
char a[1000][100];
char b[1000][100];
char c[1000][100];
int nc=1;
void inputerror(string tmp){
cout<<tmp<<" is not an available instruction\n";
}
void error1(){//Must have extension name
cout<<"Must have extension name\n";
}
void error2(string tmp){//The file extension could not be created
cout<<"The file extension "<<tmp<<" could not be created\n";
}
void error3(){
cout<<"The file could not be found\n";
}
void error4(){
cout<<"File deletion failed\n";
}
void success1(){
cout<<"File created successfully\n";
}
void success2(){
cout<<"File erased successfully\n";
}
void success3(){
cout<<"File writed successfully\n";
}
void success4(){
cout<<"Letters in the file erased successfully\n";
}
int change(string s){
int l=0;
for(int i=s.size()-1;i>=0;i--){
if(s[i]=='.'){
l=s.size()-1-i;
}
}
int f=1,idx=0;
for(int i=s.size()-1;i>=0;i--){
if(s[i]!='.'){
idx+=(s[i]-'0')*f;
f*=10;
}
}
if(l==0)return idx;
}
bool Find(char t[]){
fstream _file;
_file.open(t, ios::in);
if(!_file)return 1;
return 0;
}
string getsuffix(char t[]){
string tmp="";
for(int i=0;i<strlen(t);i++){
if(t[i]=='.'){
for(int j=i;j<strlen(t);j++){//get the file extension
tmp=tmp+t[j];
}
}
}
return tmp;
}
void createfile(char t[]){
string tmp=getsuffix(t);
if(tmp!=".txt"&&tmp!=".doc"&&tmp!=".docx"){
if(tmp==""){
error1();
}
else{
//error2(tmp);
error3();
}
}
else{
pFile=fopen(t,"w");
fclose(pFile);
success1();
}
}
void openfile(char t[]){
if(Find(t))error3();
else{
cout<<"These are the letters in "<<t<<" :\n";
FILE *fp;
char c;
//Open the file and set to pointer fp
fp = fopen(t,"r");
//Read file character by character and
//put to the standard ouput
while(1) {
c=fgetc(fp);
if(feof(fp)){
break ;
}
printf("%c", c);
}
//Close the file pointer
cout<<"\n";
fclose(fp);
cout<<"End of reading\n";
}
}
void writefile(char t[]){
if(Find(t))error3();
else{
int n=nc;
string b[100];
cout<<"Please enter the character you want to write. \nMultiple lines can also.\nPlease end with '#' \nPlease write:\n";
FILE *fp;
fp = fopen(t,"a");//get file
while(1){
nc++;
getline(cin,b[nc]);
if(b[nc]=="#")break;
for(int i=0;i<b[nc].size();i++){
c[nc][i]=b[nc][i];
}
}
for(int i=n+1;i<nc;i++){//put letters
fputs(c[i],fp);
fputs("\n",fp);
}
fclose(fp);
success3();
}
}
void erase(char t[]){
if(Find(t))error3();
else{
if(!remove(t))success2();
else error4();
}
}
void eraseletter(char t[]){
if(Find(t))error3();
else{
pFile=fopen(t,"w");
fclose(pFile);
success4();
}
}
void shutdown(char t[]){
char cmds[25]="shutdown -s -t ";
int n=strlen(cmds);
for(int i=0;i<strlen(t);i++){
cmds[n]=t[i];
n++;
}
system(cmds);
}
void Check(char t[]){
FILE * pFile;
long long size;
pFile = fopen (t,"rb");
if (pFile==NULL){
error3();
//fclose(pFile);
}
else{
//file type
string tmp=getsuffix(t);
cout<<"text file : "<<tmp<<"\n";
//file size
fseek (pFile, 0, SEEK_END);
size=ftell (pFile);
fclose (pFile);
cout<<"Size : "<<(size+1023)/1024<<" KB\n";
}
}
/*void Change(char t[]){
cout<<"Please enter the changed file name:\n";
string t;
getline(cin,t);
string path = m_strPath + '\\' + filename;
newname = m_strPath + '\\' + t;
if (-1 == rename(path.c_str(), newname.c_str())){
return false;
}
return true;
}*/
int main(){
SetConsoleTitle("FENSONWIN");
system("mode con cols=70 lines=15");
mciSendString("play music/mus_fallendown2.mp3 repeat", 0, 0, 0);
cout<<"Welcome to the FENSONWIN instruction operating system!\n";
int time=0;
while(1){
time++;
ta="";
cout<<"FENSONWIN>";
getline(cin,ta);
for(int i=0;i<ta.size();i++)a[time][i]=ta[i];
string tmp="";
int f=-1,tf=1;
for(int i=0;i<strlen(a[time]);i++){
if(i>=1&&a[time][i-1]==' '&&f==-1)f=0;
if(a[time][i]==' ')tf=0;
if(tf)tmp=tmp+a[time][i];
else{
b[time][f]=a[time][i];
f++;
}
}
if(tmp=="create")createfile(b[time]);
else if(tmp=="open")openfile(b[time]);
else if(tmp=="write")writefile(b[time]);
else if(tmp=="erase")erase(b[time]);
else if(tmp=="eraseletter")eraseletter(b[time]);
else if(tmp=="shutdown")shutdown(b[time]);
else if(tmp=="check")Check(b[time]);
//else if(tmp=="changen")Change(b[time]);
else if(tmp=="changel");
else if(tmp=="shutdown-a")system("shutdown -a");
else if(tmp=="")continue;
else inputerror(tmp);
}
return 0;
}
我的,就是音乐穿不了,随便看看吧
附上用法:
create ...
创建 ...
open ...
(用FENSONWIN)打开 ...
erase ...
删除 ...
eraseletter ...
删除 ...文件中的内容
check ...
查看 ...属**
shutdown-a
取消关机,重启,注销等任务
加油~!