Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.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
C++ 如何将二维字符类型数组按行保存到c中的.txt文件中?_C++_Arrays_Multidimensional Array - Fatal编程技术网

C++ 如何将二维字符类型数组按行保存到c中的.txt文件中?

C++ 如何将二维字符类型数组按行保存到c中的.txt文件中?,c++,arrays,multidimensional-array,C++,Arrays,Multidimensional Array,我有一个二维字符数组[100][100],我想把它按行保存到一个.txt文件中。按行排列,我的意思是首先打印第一行中的所有字符,然后打印第二行,依此类推 我可以为控制台输出编写代码,但不知道如何将其保存到.txt文件: for (int x=0;x<100;x++) { for(int y=0;y<100;y++) { cout<<array[x][y]; } } 用于(int x=0;x#包括 #包括 使用名称空间std; in

我有一个二维字符数组[100][100],我想把它按行保存到一个.txt文件中。按行排列,我的意思是首先打印第一行中的所有字符,然后打印第二行,依此类推

我可以为控制台输出编写代码,但不知道如何将其保存到.txt文件:

for (int x=0;x<100;x++)
{
    for(int y=0;y<100;y++)
    {
        cout<<array[x][y];
    }
}
用于(int x=0;x
#包括
#包括
使用名称空间std;
int main(){
流文件;
myfile.open(“example.txt”);
对于(int x=0;x请尝试以下方法:

#include <fstream>

int main()
{
    std::ofstream out("file_to_store_the_array.txt");
    for(int x = 0; x < 100; x++) {
        for(int y = 0; y < 100; y++) {
            out << array[x][y];
        }
    }
    out.close();
    return 0;
}
#包括
int main()
{
std::ofstream out(“file_to_store_the_array.txt”);
对于(int x=0;x<100;x++){
对于(int y=0;y<100;y++){
out
#包括
#包括
使用std::cout;
int main(){
流输出(“file_name.txt”);

for(int x=0;xHave your search bit on google?找出
的内容,别忘了添加一个whatever。这些都不能回答我的问题:(@user1486008:google搜索字符串“write to file c++”的顶部结果)详细说明如何做你想做的事。付出一点努力。我们不是来为你做工作的。实际上它是
endl
,而不是
endl
#include <fstream>

int main()
{
    std::ofstream out("file_to_store_the_array.txt");
    for(int x = 0; x < 100; x++) {
        for(int y = 0; y < 100; y++) {
            out << array[x][y];
        }
    }
    out.close();
    return 0;
}
#include<iostream>
#include<fstream>
using std::cout;

int main(){
ofstream out("file_name.txt");
for(int x=0;x<100;x++){
        for(int y=0;y<100;y++){

              out << array[x][y];
        }
        out << "\n";


}
file.close();
return 0;


}