c++ - 无法将数据输出到文本文件中

标签 c++

我正在试验一些将信息输出到文件的代码。文件地址似乎是正确的,代码可以编译,但文件永远不会填充。你能看出问题吗?

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
    int size = 10;
for(int i=0; i<size; ++i)
{
    ofstream outputfile;
    outputfile.open("C:MyFolder\outputfile.txt", ios::app);
    outputfile << "SYMBOL, STOCK_PRICE" << endl;
    outputfile << i << endl;
    outputfile.close();
}

}

最佳答案

当将路径修复为实际的 Windows 路径时,它对我来说运行正常;

outputfile.open("C:\\MyFolder\\outputfile.txt", ios::app);

关于c++ - 无法将数据输出到文本文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9264496/

相关文章:

c++ - QtCreator——显示一个类的成员函数列表?

C++ 在类中创建 ifstream/ofstream,与预制文本文件相关联

c++ - 使用 BLAS 和 LAPACKE 在 C++ 中使用 SVD 计算伪逆

c++ - 为什么 '::' 、 '.' 、 '?:' 等运算符不能在 C++ 中重载?

c++ - 防止用户从不正确的 CRTP 基础派生

c++ - 我没有正确编程我的 while 循环

c++ - 这段代码有什么作用? (关于指针)

c++ - 如何在 QPlainTextEdit 中只读一行?

c++ - 使用顶点缓冲区的直接状态访问

C++如何删除一个结构?