fstream代码未在我的桌面上创建文件 我是C++编程新手,遇到了一个问题。我将代码块IDE与它附带的默认编译器一起使用
我的问题是,为什么我写这段代码时没有在我的桌面上创建一个文件fstream代码未在我的桌面上创建文件 我是C++编程新手,遇到了一个问题。我将代码块IDE与它附带的默认编译器一起使用,c++,file-io,C++,File Io,我的问题是,为什么我写这段代码时没有在我的桌面上创建一个文件 #include <iostream> #include <fstream> using namespace std; int main() { ofstream output; output.open("Desktop\\demofile.txt"); cout << "Now writing data to file" << endl; // wr
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream output;
output.open("Desktop\\demofile.txt");
cout << "Now writing data to file" << endl;
// write four names to file
output << "Bach" << endl;
output << "Beethoven" << endl;
output << "Mozart" << endl;
output << "Schubert" << endl;
output.close();
cout << "Done!" << endl;
return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
流量输出;
output.open(“Desktop\\demofile.txt”);
cout因为文件(您正在使用的文件)的相对路径通常从程序启动的目录开始(但是IDE可以更改)
确保使用完整路径(C:\…)
- 只要换上你的
output.open("Desktop\\demofile.txt");
下线
output.open("Desktop//demofile.txt");
- 表示使用正斜杠而不是反斜杠
为什么您认为以“Desktop\\”开头的路径将是桌面?另一个采用endl
惯例的初学者:-(