ファイルから入力を読み込み、区切り文字の前にスペースを入れ、別のファイルに書き込むためのC++プログラムを作ろうとしています。 例: 入力: int型のmain() 出力: int型のmain()C++のエラー、出力なし
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
fstream oup, inp;
int dsize = 18;
char delim[] = {',', ' ', '\n', '\t', '\"', '(', ')', '{', '}',
'\'', '[', ']', '+', '-', '*', '&', '/', '%'};
bool isDelim(char c) {
for (int i = 0; i < 18; i++)
if (c == delim[i])
return true;
return false;
}
void chartost(string a) {
int d = 0;
if (a.length() == 1)
oup << a << " ";
else {
for (unsigned i = 0; i < a.length(); i++) {
if (isDelim(a[i])) {
d = 1;
oup << a.substr(0, i) << " ";
chartost(a.substr(i, a.length()));
}
}
if (d == 0) {
oup << a << " ";
}
}
}
int main() {
cout << "Initial Point";
inp.open("test.c", ios::in);
oup.open("testspace.c", ios::out);
string a;
cout << "before isopen";
if (inp.is_open() && oup.is_open()) {
while (inp >> a) {
cout << a;
chartost(a);
}
cout << "after operations \n";
inp.close();
oup.close();
}
return 0;
}
私は多くの場所ではcoutを使用しましたデバッグします。 私はこれのためにセグメンテーションフォルトを得ています、そして、メインのエントリーポイントでのcoutさえ表示されていません。
動作中のクラッシュをキャッチするためにデバッガで実行してみてください。それは、あなたのコードのどこでクラッシュが発生するのかを特定するのに役立ちます。また、関連する変数の値を調べることもできます。 –
また、 'cout'ステートメントが出力の後に' endl'ステートメントが置かれていることを保証するために。 –
コードブロック - 警告:GDB:制御端末の設定に失敗しました:操作が許可されていません –