gpt4 book ai didi

c++ - 没有得到 cout 的输出

转载 作者:行者123 更新时间:2023-11-28 05:45:40 28 4
gpt4 key购买 nike

我有一个与链表有关的项目。截至目前,我只想输出我所拥有的,这样我就可以看到我在做什么,看看我在哪里,但我什至无法做到这一点。

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;
struct node;
typedef node* nodePtr;

struct node {
int x;
int hour;
int minute;
string owner_name;
string pet_name;
node* next;
};

void CreateList(nodePtr first, ifstream& inFile);
void PrintList(nodePtr first);
int main()
{
nodePtr first;
ifstream inFile("vetAppts.txt");
if (inFile.fail()) {
cout << "can't open the input file" << endl;
}
else {
cout << "input file is open" << endl;
}
return 0;
cout << "dsadsa";
CreateList(first, inFile);
PrintList(first);
}
void CreateList(nodePtr first, ifstream& inFile) {
nodePtr newApp;
newApp = new node;
first = NULL;
while (!inFile.eof()) {
inFile >> first->hour;
inFile.get();
inFile >> first->minute;
getline(inFile, first->owner_name);
getline(inFile, first->pet_name);

}
cout << first->hour << first->minute << first->owner_name << first->pet_name;
}

我唯一的输出是“输入文件已打开”。

最佳答案

……

if (inFile.fail()) {
cout << "can't open the input file" << endl;
}
else {
cout << "input file is open" << endl;
}
//return 0;

....

注释这个return 0;,这会让你程序退出。

关于c++ - 没有得到 cout 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36274879/

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