gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:41:00 24 4
gpt4 key购买 nike

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

#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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com