私は、引数ベクトルを使用して2つのテキストファイルを取り込み、最初のものを入力、2番目のものを出力/空白ファイル)に変更し、の単語(単語のみ - 文字のみを含むとみなされる)または単語の文字を同じ文字数のの数字で変更して入力ファイルをデコードし、各数字を " 0 "、その他のもの(文字、数字、句読点)を" x "に置き換えます。デコードされたファイルを出力ファイルにコピーし、それぞれの文字列(単語、数値、混合)の間に同じ数のスペースと行を維持します。ファイル内の文字列の文字を別の特定の文字に変更することによってテキストファイルを別のものに復号する
注:入力の行は限定しないでください!
問題:それは各行 を終えた後の行を入力していない
は率直に言って、私は何かを書き、それが部分的に動作し、各文字列を読んだ後と復号化を行うと、出力ファイルにデコードされた複写そのため、同じ 行にあるように、連続してデコードされたすべての文字列が出力されます。ここで
はコードです:例えば
void read_line(ifstream &inp_f,ofstream &out_f)
{
char c,
str[MAX_STR_LEN],// holds the string that working on
prev_str[MAX_STR_LEN]; // holds the previous string
int count_spaces=-1,
count_entered=0, // how many chars are in the array including '\0'
counter[CNTR_LEN];// holds the number of each type of string in the line
bool read=false,copy=false;
while(!inp_f.eof())
{
c=inp_f.get();
if(!isspace(c) && c!='\n')
{
str[count_entered]=c;
count_entered++;
read=true;// only if something has been read except spaces in the line
copy=true;// used to give the command to copy the char to the string array
}
else if(isspace(c) || c=='\n')// when reading a space or one line
{
count_spaces++;
str[count_entered]='\0';
if(copy && strcmp(prev_str,str)!=0)
{
strcpy(prev_str,str);
decode(counter,str);// Decoding the string considering it's type
copy_str(count_spaces,str,counter,out_f); // when all the string has been read,copy it to the output file
count_entered=0;
count_spaces=0;
copy=false;
}
///////////////// can't take it to enter here /////////////////////////
else if((!copy || !read) && c=='\n') // when finishing one line
{
out_f << endl;
// print how many strings there of each type in the current line
cout << counter[0] << " " << counter[1] << " "
<< counter[2] << endl;
// re-initial the counters for the next line!
for(int i=0;i<CNTR_LEN;i++)
{
counter[i]=0;
}
}
}
}
}
:
入力:ちょうど11500年前に住んで
未知の人類は15で発見された中国南部、 で識別されています/ 03/12または先月3日
出力:
AAAAAAA AAAAA AAAAAAA AAAAAA AAAA 00000 AAAAAのaaa AAAのAAAAAAAAAA AA aaaaaaaaをXXXXXX AAAAAのAAAAAAAAAA AAのXXXXXXXXのAA、AAA xxxの単三AAAAのAAAAA
のようになりますあなたはそれをファイルに書き込んで改行を得るか、書かれた文字列の後に '\ n'を書いていますか? – twain249
私は分割された行にすべての文字列(単語や数字など)を必要としません!私は段落のように行にそれらをしたい! –
それでは、何とか線のサイズを制限する必要があります。それぞれの行の長さを数え、ある点に達したときに '\ n'文字を追加することができます。 – twain249