这是我将其归结为简单的 open() 的代码,打开文件输入语句显示但关闭文件没有。这在空闲界面中运行,但不在命令行界面中运行。
程序和文件(拼写正确且全部小写)都在桌面上用于此测试。有没有人看到缺少什么?打开
# Read It
# Demonstrates reading from a text file
input("\n\nPress the enter key to Open file")
print("Opening and closing the file.")
text_file = open("nicole1.txt", "r")
input("\n\nPress the enter key to Close file")
text_file.close()
input("\n\nPress the enter key to exit.")
Run Code Online (Sandbox Code Playgroud)
** 更新,好的,我尝试了绝对路径,没有成功。我在闪存驱动器上有一个副本。我在 Windows XP 机器和 Windows 7 机器上运行它,它运行得很好。我使用相同的闪存驱动器并尝试在 Windows10 Box 上运行它,但我遇到了问题。一条评论询问是否有回溯,并且有,它基本上表明该文件不存在。我现在正在尝试确定这是否是 Windows 10 问题。此外,代码将在两个 Windows Box(XP 和 Win10)上的 idle 内运行。
在下面的代码中,我试图创建一个函数"patient_count",它是"horse","pig"和"dog"类的朋友.我可以让这个功能成为一个班级的朋友而不是所有的3个人.任何人都能告诉我我的错误是什么吗?
/*******************************************************\
* Veternarian Class Problem - I need a class for each *
* of 3 animals. Horse, Pig and Dogs *
\*******************************************************/
#include <cstdlib>
#include <iostream>
#include <string>
const int HORSE_KENNEL = 100; // Number of horses we can store
const int PIG_KENNEL = 100; // Number of Pigs we can store
const int DOG_KENNEL = 100; // Number of Dogs we can store
/*******************************************************\
* Class horse *
* *
* Member functions *
* horse_count -- …Run Code Online (Sandbox Code Playgroud)