gpt4 book ai didi

无法加载 C++ 文本文件

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

所以我的驱动看起来像这样:

#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 放在同一个文件夹中,它在我几天前刚试过的另一台电脑上工作。现在,每次我尝试运行它时,它都会直接给我“无法打开文件”。我不知道出了什么问题。我什至把一个 text.txt 和 c++.sln 放在同一个目录,另一个和我的 .cpp 和 .h 文件放在同一个目录,只是为了确保有一个 text.txt 可以打开。

首先,我尝试通过 Xcode,将我的 text.txt 放在项目目录以及 .cpp 和 .h 目录中。无法打开文件。

然后,我厌倦了 visual-studio,我确实将 .txt 放在与我的 .exe 相同的目录中。“CMD.EXE 以上述路径作为当前目录启动。不支持 UNC 路径。默认为 Windows 目录。文件无法打开”

最佳答案

答案在此错误消息中:

"CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. File could not be open"

您正在从网络共享启动 .exe,cmd.exe 将您的工作目录更改为 %WINDOWS% 目录。然后程序尝试通过相对文件名打开文件并且肯定会失败。将 exe 和文本文件复制到本地文件夹,它会正常工作。

关于无法加载 C++ 文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35819227/

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