【问题标题】:C++ write data on array in fileC ++在文件中的数组上写入数据
【发布时间】:2016-06-02 10:57:11
【问题描述】:

我想用 C++ 代码将这些数据写入文件中的数组 请帮帮我! 这段代码很好,但我想把它写在数组上! 我应该添加什么来将它写在数组上!

#include <iostream>
    #include <fstream>
    #include<string>
    using namespace std;
    int main(){
            ofstream file("BooksList.txt");
        if (file.is_open()){

                   file <<"[1]Programming Languages:Principles and Practice\t\tKenneth C. Louden\t\t\t0534953417"<<endl;
                   file <<"[2]Programming Languages:Principles and Paradigms\t\tAllen Tucker and Robert Noonan\t\t0071122800"<<endl;
                   file <<"[3]File Structures:An Object-Oriented Approach with C++\t\tMichael Folk and Bill Zoellick\t\t0201874016"<<endl;
                   file <<"[4]Data Structures Using C++\t\t\t\t\tD.S Malik\t\t\t\t0324782012"<<endl;
                   file <<"[5]Fundamentals of Web Development\t\t\t\tRandy Connolly\t\t\t\t0133407152"<<endl;
                   file <<"[6]Data Structures and Algorithms in Java\t\t\tGoodrich and Tamassia\t\t\t0471738840"<<endl;

            cout<<"written successfully !";

         }else{
              cout<<"File Not Found !- ERROR";
            }

          return 0;
    }

【问题讨论】:

  • 我不明白这个问题。 “将此数据写入文件中的数组”是什么意思?

标签: c++ arrays file main ostream


【解决方案1】:
ofstream file;
file.open("BooksList.txt");

在这之后你可以做文件

【讨论】:

  • 但我真的不确定这是否是你的问题,因为你也在谈论数组。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-16
  • 2013-09-07
  • 2014-08-18
相关资源
最近更新 更多