Visual Studio在Desktop目录中查找文件而不是Project Directory

时间:2015-08-07 09:46:42

标签: c++ visual-studio-2010 visual-c++ file-io

我正在尝试在“Start Without Debugging”和“Release”模式下运行以下代码。

#include<iostream>
#include<string>
using namespace std;

int main() {

string word;
freopen("test.txt","r",stdin);
if(cin>>word)
    cout<<word;
else
    cout<<"unable to read"<<endl;
return 0;
}

在Debug模式下一切正常,但是当我在Start without Debugging模式或release模式下运行代码时,输​​出总是“无法读取”,除非该文件在Project文件夹中。

如果文件放在桌面目录中,代码可以正常工作,那会有什么不好。 任何人都可以解释为什么Visual Studio在不在调试模式时在桌面而不是项目文件夹中查找文件?

0 个答案:

没有答案
相关问题