C++ 从项目VS2013外部打开并读取文件
我无法从项目外部读写文件。添加现有项目时没有链接选项,请提供帮助。您的意思是要添加该文件作为对项目的引用,还是要使用代码修改文件中的数据 如果要添加文件并在项目中引用它,应该可以通过右键单击项目名称,然后单击C++ 从项目VS2013外部打开并读取文件,c++,c,visual-studio,C++,C,Visual Studio,我无法从项目外部读写文件。添加现有项目时没有链接选项,请提供帮助。您的意思是要添加该文件作为对项目的引用,还是要使用代码修改文件中的数据 如果要添加文件并在项目中引用它,应该可以通过右键单击项目名称,然后单击 Properties->Common Properties->References->Add New Reference->Browse 然后找到要引用的文件 对于文件的读取和写入,您可以#include并分别使用std::ifstream和std::ofstream进行输入和输出 你可以
Properties->Common Properties->References->Add New Reference->Browse
然后找到要引用的文件
对于文件的读取和写入,您可以#include
并分别使用std::ifstream
和std::ofstream
进行输入和输出
你可以这样做:
#include <fstream>
#include <string>
#include <iostream>
using std::ifstream;
using std::ofstream;
using std::string;
using std::cout;
using std::endl;
void main() {
string file = "C:\\Users\\Foo\\Desktop\\Bar.txt";
ofstream output(file);
output << "Hello World" << endl;
output.close();
ifstream input(file);
string inputStr;
while(input >> inputStr) {
cout << inputStr << endl;
}
return;
}
#包括
#包括
#包括
使用std::ifstream;
使用std::of流;
使用std::string;
使用std::cout;
使用std::endl;
void main(){
string file=“C:\\Users\\Foo\\Desktop\\Bar.txt”;
流输出(文件);
输出输入(STR){
库特