无法加载C++文本文件
C++ text file cannot be loaded
所以我的驱动程序看起来像这样:
#include "problem2.h"
#include "problem1.h"
#include "problem3.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
using namespace std;
template <typename T>
T convertString (std::string str){
T ret;
std::stringstream ss(str);
ss >>ret;
return ret;
}
int main()
{
ifstream infile("text.txt", ios::in);
if(!infile)
{
cerr <<"File could not be opend"<<endl;
}
SortedLinked mylist;
int a;
int b;
string c;
string d;
string e;
int f;
char g;
string h;
string mystr;
int mymin;
int mysec;
while(infile>>a>>b>>c>>d>>e>>f>>g>>h)
{
mystr = a+b;
mymin = convertString<int>(e.substr(0,2));
mysec = convertString<int>(e.substr(3, 4));
replace(h.begin(), h.end(), '_', ' ');
Runner M(mystr, f, mymin, mysec);
mylist.additem(M);
}
return 0;
}
我将text.file放在同一个文件夹中,它在我几天前刚刚尝试的另一台PC上工作。现在,每次我尝试运行它时,它都会直接给我"文件无法打开"。我不知道出了什么问题。我甚至把一个文本.txt放在与 c++.sln 相同的目录中,另一个放在与我的 .cpp 和 .h 文件相同的目录中,只是为了确保有一个文本.txt可以打开。
首先,我尝试通过Xcode,我将文本.txt放在项目目录和.cpp和.h目录中。无法打开文件。
然后,我通过可视化工作室感到疲倦,我确实.txt与我的.exe放在同一个目录中。"CMD.EXE 以上述路径作为当前目录启动。不支持 UNC 路径。默认为 Windows 目录。文件无法打开"
答案在此错误消息中:
"CMD.EXE 以上述路径作为当前目录启动。北卡罗来纳大学 不支持路径。默认为 Windows 目录。文件可以 不开门"
您正在从网络共享和 cmd 启动.exe.exe将工作目录更改为 %WINDOWS% 目录。然后程序尝试按相对文件名打开文件,但肯定失败。将exe和文本文件复制到本地文件夹,它可以正常工作。
相关文章:
- 文本文件中的单词链表
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 如何将内容数组写入文本文件?
- 无法通过空白将文本文件行分隔为矢量
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- C++将文本文件中的数据读取到结构数组中
- 在指针的帮助下,文本文件中单词的频率
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 将值从二维数组输出到文本文件
- 如何在c++中从文本文件中逐行读取整数
- 从文本文件中读取时钟时间和事件时间并进行处理
- 如何从文本文件中读取值和数组
- 如何在C++中确定文本文件中的元素是字符还是数字
- C++试图读取一个文件并输出到另一个文本文件
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 已修改的LinkedList未在文本文件本身中更新
- C++文本文件的获取线
- 为什么C++的文件 I/O 在读取文本文件时忽略初始空行?我怎样才能让它不这样做?
- 打印逐行存储的文本文件
- C++文本文件输入