C++将数据写入文件中的数组

C++ write data on array in file

本文关键字:数组 文件 数据 C++      更新时间:2023-10-16

我想用 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 PracticettKenneth C. Loudenttt0534953417"<<endl;
                   file <<"[2]Programming Languages:Principles and ParadigmsttAllen Tucker and Robert Noonantt0071122800"<<endl;
                   file <<"[3]File Structures:An Object-Oriented Approach with C++ttMichael Folk and Bill Zoellicktt0201874016"<<endl;
                   file <<"[4]Data Structures Using C++tttttD.S Maliktttt0324782012"<<endl;
                   file <<"[5]Fundamentals of Web DevelopmentttttRandy Connollytttt0133407152"<<endl;
                   file <<"[6]Data Structures and Algorithms in JavatttGoodrich and Tamassiattt0471738840"<<endl;
            cout<<"written successfully !";
         }else{
              cout<<"File Not Found !- ERROR";
            }
          return 0;
    }
ofstream file;
file.open("BooksList.txt");

在此之后,您可以执行文件<<"数据"