无法加载 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 放在同一个文件夹中,它在我几天前刚试过的另一台电脑上工作。现在,每次我尝试 运行 它时,它都会直接给我 "File could not be open"。我不知道出了什么问题。我什至把一个 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和文本文件到本地文件夹就可以了
所以我的驱动看起来像这样:
#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 放在同一个文件夹中,它在我几天前刚试过的另一台电脑上工作。现在,每次我尝试 运行 它时,它都会直接给我 "File could not be open"。我不知道出了什么问题。我什至把一个 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和文本文件到本地文件夹就可以了