我有一个与链表有关的项目。截至目前,我只想输出我所拥有的,这样我就可以看到我在做什么,看看我在哪里,但我什至无法做到这一点。
#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/