作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 C++ 编程的新手,遇到了一个问题。我将代码块 IDE 与它附带的默认编译器一起使用。
我的问题是,当我编写这段代码时,为什么没有在我的桌面上创建一个文件?
#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;
}
最佳答案
因为文件(您正在使用的文件)的相对路径通常从程序启动的目录开始(但 IDE 可以更改它)。
确保使用完整路径 (C:\...)
关于c++ - fstream 代码没有在我的桌面上创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31881257/
我是一名优秀的程序员,十分优秀!