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

标签 c++

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

#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/

相关文章:

c++ - 如何从 std::vector<string> 构造 std::string?

c++ - std::cout operator<< 的奇怪行为

c++ - 如何在目录中以特定格式获取行的特定部分?

C++原始字符串unicode文字

c++ - 等于指针值正在改变指针引用

c++ - 如何在 C++ 中创建列表?

c++ - 通过引用传递,仅限子范围?

c++ - 这个声明作为英文句子的确切含义是什么?

c++ - 我们如何将 C++ 类对象作为值存储在 Redis 数据库中?

c++ - std::bind 是否丢弃 C++11 中参数的类型信息?