程序继续运行,没有任何输出
Program continues to run without any output
这里是初级程序员。下面的代码能够运行而不输出任何错误;但是,它不输出任何内容,并且永远不会停止运行。而且,我花了无数个小时也弄不明白为什么会这样。
struct包含动态数组,用于在读取文件后存储整数和字符串。该文件(weatherdata.txt)包含城市名称、高温和低温的列表。然后,在读取这些行之后,将它们存储到动态数组中,并在必要时将动态数组的大小加倍(大小加倍)。
要查看这是否有效,我想输出城市列表,但这不起作用。我的代码写错了吗?
#include <iostream>
#include <fstream>
using namespace std;
//Declaring struct
struct dynArr{
string *cityName;
int *hiTemp;
int *loTemp;
int size;
};
//Function read in the desired file
void openFile ( dynArr & arr1 ){
arr1.size = 10;
arr1.cityName = new string[arr1.size];
arr1.hiTemp = new int[arr1.size];
arr1.loTemp = new int[arr1.size];
string city;
int hi, lo;
ifstream is;
is.open ("weatherdata.txt ", ios::in);
int i = 0;
is >> city;
while ( ! is.eof() ){
is >> hi >> lo;
//Double the size of dynamic arrays
if ( i >= arr1.size){
string *tempStr1;
tempStr1 = new string[arr1.size*2];
int *tempInt1;
tempInt1 = new int[arr1.size*2];
int *tempInt2;
tempInt2 = new int[arr1.size*2];
for (int a = 0; a < arr1.size; a++){
tempStr1[a] = arr1.cityName[a];
tempInt1[a] = arr1.hiTemp[a];
tempInt2[a] = arr1.loTemp[a];
}
delete[] arr1.cityName;
delete[] arr1.hiTemp;
delete[] arr1.loTemp;
arr1.cityName = tempStr1;
arr1.hiTemp = tempInt1;
arr1.loTemp = tempInt2;
arr1.size = arr1.size*2;
}
//Store the read lines from file into the dynamic arrays
arr1.cityName[i] = city;
arr1.hiTemp[i] = hi;
arr1.loTemp[i] = lo;
i++;
is >> city;
}
for (int a = 0 ; a < i ; a++)
cout << a << ". " << arr1.cityName[a] << endl;
}
int main(int argc, char *argv[]) {
dynArr arr1;
openFile(arr1);
}
文件名和右引号之间有一个空格
is.open ("weatherdata.txt ", ios::in);
相关文章:
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 代码编译没有任何输出,入门程序
- 可能我知道为什么这段代码没有给出任何输出吗?
- 什么是现实中的"endl"(或任何输出操纵器)?它是如何实现的,它如何与操作员<<一起工
- 为什么下面的Hello World程序在PowerShell上没有显示任何输出?同一程序在CMD上显示正确的输出
- 执行此代码时,它不显示任何输出.为什么?
- 合并排序没有给我任何输出
- 编译器没有显示错误,但我没有得到任何输出.怎么了?
- 当我从头文件和实现文件调用我的函数到我的主文件时,我没有得到任何输出
- 为什么我在链表中插入的代码没有得到任何输出?
- 后缀Expressrion的插图未显示任何输出
- 不显示任何输出
- VS Code C++程序在调试时不显示任何输出
- 当我使用继续时,程序不提供任何输出
- 该代码在 Dev-C++ 中没有给我任何输出
- Cereal 找不到任何输出序列化函数
- C++ 中的侵蚀函数不给出任何输出
- Ocamlopt不会产生任何输出,只有错误代码
- 当我从java代码执行C++时不显示任何输出
- 这个看似无害的代码不会产生任何输出