所以我的驱动程序看起来像这样:
#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上运行。现在,每次我试图运行它,它只是直接给我&#34;文件无法打开&#34;。我不知道出了什么问题。我甚至将一个text.txt放在与c ++。sln相同的目录中,另一个放在与.cpp和.h文件相同的目录中,只是为了确保有一个text.txt可以打开。
首先,我尝试通过Xcode,我将text.txt放在项目目录和.cpp和.h目录中。文件无法打开。
然后,我厌倦了visual-studio,我把.txt放在与我的.exe相同的目录中。 &#34; CMD.EXE以上述路径作为当前目录启动。 不支持UNC路径。默认为Windows目录。 文件无法打开&#34;
答案 0 :(得分:3)
答案出现在以下错误消息中:
&#34; CMD.EXE以上述路径作为当前目录启动。 UNC 路径不受支持。默认为Windows目录。文件可以 不公开&#34;
您正在从网络共享启动.exe,cmd.exe会将您的工作目录更改为%WINDOWS%目录。然后程序尝试通过相对文件名打开文件,肯定会失败。将exe和文本文件复制到本地文件夹,它可以正常工作。