c++中的分段故障,无输出
Segmantation fault in c++, no output
我正在尝试制作一个C++程序来读取文件中的输入,在分隔符之前放置空格,并写入另一个文件。示例:输入:int main()输出:int main()
#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也没有显示。
代码一团糟,很难发现错误,但我注意到您的chartost函数是递归的,但在递归退出时不会终止。第一个调用的for循环将在代码对字符串的其余部分进行递归后处理字符串的剩余部分。我会从那里开始寻找你的问题。
相关文章:
- 分段故障(堆芯转储)矢量
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- C++中的动态铸造故障
- 请解释"函数1(p1,p2,p3);"的输出
- 数组的指针从不分段故障
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 插入std :: basic_ostream实例化输出时的内存故障
- c++中的分段故障,无输出
- 输出出现分段故障
- 程序接收信号SIGSEGV,输出分段故障
- 输出功能C++出现故障
- c++程序中的段故障难以理解的valgrind输出
- C++-调整输出时出现故障