Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
fstream代码未在我的桌面上创建文件 我是C++编程新手,遇到了一个问题。我将代码块IDE与它附带的默认编译器一起使用_C++_File Io - Fatal编程技术网

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
惯例的初学者:-(