//
#include <bits/stdc++.h>
#include <windows.h>
//#include "ph_del.h"
#include <vector>
#include <direct.h>
//#include <fstream>
using namespace std;
void method(int meth,string folder,string ss,string origin);
string input_path(string *file_name);
bool input_file(char *c,string *ss);
void reject(string *ss);
bool save(string file_name,string ss,string origin);
string del_space(string ss,int *ret);
string sim_sen(string ss);
int main()
{
string file_name;
string ss;
string path=input_path(&file_name);
char *c=(char*)path.c_str();
if(!input_file(c,&ss))return 0;
string origin=ss;
reject(&ss);
save(file_name,ss,origin);
return 0;
}
void method(int meth,string folder,string ss,string origin)
{
switch(meth)
{
case 1:
//string path_1=
ofstream fout_1((char*)(folder+"Normal.docx").c_str(),ios::out);
fout_1<<ss;
fout_1.close();
break;
case 2:
ofstream fout_2((char*)(folder+"Simple Sentence.docx").c_str(),ios::out);
fout_2<<sim_sen(ss);
fout_2.close();
break;
case 3:
ofstream fout_3((char*)(folder+"Original.docx").c_str(),ios::out);
fout_3<<origin;
fout_3.close();
break;
case 4:
ofstream fout_4((char*)(folder+"Non-space.docx").c_str(),ios::out);
int i;
string sss=del_space(&ss,&i);
fout_4<<sss;
fout_4.close();
break;
default:
ofstream fout_faulty((char*)(folder+"ERROR.txt").c_str(),ios::out);
fout_faulty.close();
}
return;
}
string input_path(string *file_name)
{
string path;
cout<<"Please enter the path:";cin>>path;
int slash_pos=path.rfind('/');
if(slash_pos==-1)
{
slash_pos=path.rfind('\\') ;
slash_pos+='\\';
}
else
{
slash_pos+='/';
}
int dot_pos=path.rfind('.');
*file_name=path.substr(slash_pos+1,dot_pos-slash_pos-1);
return path;
}
bool input_file(char *c,string *ss)
{
string s;
ifstream fin(c,ios::in);
if(!fin)
{
cout<<"Not found!!!\a"<<endl;
return false;
}
int cnt=0;
while (getline(fin,s,'\n'))
{
cnt++;
*ss+=s;
*ss+='\n';
}
fin.close();
return true;
}
void reject(string *ss)
{
int start_pos=ss->find('[');
if(start_pos!=-1)
{
int finish_pos=ss->find(']');
ss->erase(start_pos,finish_pos);
}
}
bool save(string file_name,string ss,string origin)
{
string save_path;
cout<<"Please enter the save path:";cin>>save_path;
string meth_store;
cout<<"Please choose the method of storage:(Space off)"<<endl;
cout<<"1.Normal \t 2.Simple Sentence"<<endl;
cout<<"3.Original \t 4.Non-space"<<endl;
cin>>meth_store;
int a[4]={0};int ia=0;
for(int i=0; i<meth_store.size(); i++)
{
if(meth_store[i]<='9' && meth_store[i]>='0')
a[ia++]=meth_store[i]-'0';
else continue;
}
string folder=save_path+file_name;
_mkdir((const char*)folder.c_str());
for(int i=0; a[i]!=0; i++)
method(a[i],folder,ss,origin);
return true;
}
string del_space(string ss,int *ret)
{
int i=0;
int cnt=3;
while(cnt)
{
char a=ss[i];
if(a=='\n')cnt--;
}
*ret=i;
for( ; i<ss.size(); i++)
{
if(ss[i]=='\n');
ss.erase(i,1);
}
return ss;
}
string sim_sen(string ss)
{
vector<string> sentence;
int start_i;
ss= del_space(ss,&start_i);
int cnt=0;
string add;
for(int i=start_i; i<ss.size();i++)
{
if(ss[i]='.')
{
sentence.push_back(add+'\n');
add.clear();
cnt++;
}
else
{
add+=ss[i];
}
}
string ret;
ret+=ss.substr(0,start_i);
for(int i=0; i<cnt; i++)
{
ret+=sentence[i];
}
return ret;
}
錯誤提示:
C:\Users\俞麗娜\Desktop\Photo_delete.cpp In function 'void method(int, std::string, std::string, std::string)':
44 8 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] jump to case label [-fpermissive]
40 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_1'
49 8 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] jump to case label [-fpermissive]
45 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_2'
40 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_1'
54 8 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] jump to case label [-fpermissive]
50 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_3'
45 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_2'
40 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_1'
57 31 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] could not convert '& ss' from 'std::string* {aka std::basic_string<char>*}' to 'std::string {aka std::basic_string<char>}'
61 3 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] jump to case label [-fpermissive]
57 11 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::string sss'
55 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_4'
50 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_3'
45 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_2'
40 13 C:\Users\俞麗娜\Desktop\Photo_delete.cpp [Error] crosses initialization of 'std::ofstream fout_1'
uj5u.com熱心網友回復:
俞麗娜是真名嗎?
uj5u.com熱心網友回復:
遇到問題,不妨先百度一下。。。。。。。。。。。參看下面的鏈接https://www.jianshu.com/p/254abfa7caed
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/17535.html
標籤:基礎類
上一篇:結構體
下一篇:數學知識
