gpt4 book ai didi

c++ - cygwin 控制台上没有错误或 cout 消息

转载 作者:太空狗 更新时间:2023-10-29 23:19:25 26 4
gpt4 key购买 nike

我在我的 Windows7 机器上安装了 cygwin,我正在运行一些 C++ 代码。当我运行这段代码时:

#include <iostream>
#include <string>
#include <fstream>
#include <time.h>
#include <math.h>
#include "Pop.h"
using namespace std;


int main() {
ifstream in;
ofstream out;
cout << "something";
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "1\n";
else
cout << "unable to open res7 file";
out.close();
int seed = time(NULL);
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "2\n";
else
cout << "unable to open res7 file";
out.close();
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "seed " << seed << '\n';
else
cout << "unable to open res7 file";
out.close();
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "3\n";
else
cout << "unable to open res7 file";
out.close();
srand (seed);
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "4\n";
else
cout << "unable to open res7 file";
out.close();
double parameters[4];
int location;
in.open("input7.txt", ios::in);
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "5\n";
else
cout << "unable to open res7 file";
out.close();
return 0;
}

我在控制台上看到一个输出(某些东西)。但是当我运行我的完整代码时:

#include <iostream>
#include <string>
#include <fstream>
#include <time.h>
#include <math.h>
#include "Pop.h"
using namespace std;


int main() {
ifstream in;
ofstream out;
cout << "something";
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "1\n";
else
cout << "unable to open res7 file";
out.close();
int seed = time(NULL);
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "2\n";
else
cout << "unable to open res7 file";
out.close();
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "seed " << seed << '\n';
else
cout << "unable to open res7 file";
out.close();
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "3\n";
else
cout << "unable to open res7 file";
out.close();
srand (seed);
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "4\n";
else
cout << "unable to open res7 file";
out.close();
double parameters[4];
int location;
in.open("input7.txt", ios::in);
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "5\n";
else
cout << "unable to open res7 file";
out.close();
if (in.is_open()) {
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "6\n";
else
cout << "unable to open res7 file";
out.close();
char line[256];
while (!in.getline(line, 256).eof()) {
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "7\n";
else
cout << "unable to open res7 file";
out.close();
char *input = strtok(line, " ");
int i=0;
while (input!=NULL) {
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "8\n";
else
cout << "unable to open res7 file";
out.close();
parameters[i] = atof(input);
input = strtok(NULL, " ");
i++;
}
int rnum = rand();
location = rnum%10000;
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "9\n";
else
cout << "unable to open res7 file";
out.close();
Pop p(parameters[0], parameters[1], 0.2, 0.1, parameters[2], location);
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "10\n";
else
cout << "unable to open res7 file";
out.close();
double L = exp(-parameters[3]);
double FF_mean = p.FF_steady(parameters[3], L, 0.0);
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "11\n";
else
cout << "unable to open res7 file";
out.close();
out.open("res7.txt", ios::out|ios::app);
if (out.is_open()) {
out << "number of chromosomes is " << p.all_population[0]->ga->chromosome << " alpha is " << parameters[2] << " cost is " << parameters[1];
out << " a is " << parameters[0] << " u is " << parameters[3] << " location is " << location << " FF steady is " << FF_mean << '\n';
}
else
cout << "unable to open res7 file FF";
out.close();
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "12\n";
else
cout << "unable to open res7 file";
out.close();
if (FF_mean>0.1) {
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "13\n";
else
cout << "unable to open res7 file";
out.close();
p.insert_O(0.05);
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "14\n";
else
cout << "unable to open res7 file";
out.close();
double total_mean = p.steady(parameters[3], L, 0.0);
double perc = p.perc_O();
out.open("res7.txt", ios::out|ios::app);
if (out.is_open())
out << "total steady is " << total_mean << " perc O is " << perc << '\n';
else
cout << "unable to open res7 file";
out.close();
}
}
}
else
cout << "Unable to open input7 file\n";
in.close();
return 0;
}

我在控制台上没有看到任何输出。当我在另一台机器上运行代码时,我发现我有一个浮点异常。我想我可以找到它的位置,但我不明白的是为什么我在 cygwin 的控制台上看不到任何输出或错误。谁能帮帮我?

最佳答案

您确定代码可以编译吗?在倒数第三行你有

in.close();*/

但是,没有开始的/* 标签。我会确保您的代码确实在编译,并且您生成了一个新的 .exe。您可能无法编译和运行没有任何 cout 的旧 .exe。

此外,您确定没有抛出异常吗?我无法完全测试代码,因为我缺少“Pop.h”的源代码,所以我无法完全看到编译时出现的错误。你能否尝试在你的程序的顶部有一个初始 cout,并可能提供 Pop.h 的源代码,以便我们可以对其进行更多测试。

关于c++ - cygwin 控制台上没有错误或 cout 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8928728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com