C ++在循环中打开多个流

时间:2017-01-25 12:47:40

标签: c++ ofstream

我需要使用ofstream打开未定义数量的文件才能写入。文件名的格式应为plot1.xpm,plot2.xpm,plot3.xpm,.... 该程序如下所示: 我不知道我应该在星星中放置什么。

for(m = 0; m < spf; m++){
    //some calculations on arr[]
    ofstream output(???);
    for(x = 0; x < n; x++){
        for(y = 0; y < n; y++){
            if (arr[x*n + y] == 0)
                output<<0;
            else output<<1;
        }
        output<<'\n';
        output.close();
    }

1 个答案:

答案 0 :(得分:1)

使用to_string

<body>
    <div id="case">
            <div id="0" class="box">
                <input> </input>
                <p class="id">0</p>
                <p class="id"></p>
            </div>
            <div id="1" class="box">
                <input></input>
                <p class="id">1</p>
            </div>
            <div id="2" class="box">
                <input></input>
                <p class="id">2</p>
            </div>
            <div id="3" class="box">
                <input></input>
                <p class="id">3</p>
            </div>
            <div id="4" class="box">
                <input></input>
                <p class="id">4</p>
            </div>
            <div id="5" class="box">
                <input></input>
                <p class="id">5</p>
            </div>
            <div id="6" class="box">
                <input></input>
                <p class="id">6</p>
            </div>
            <div id="7" class="box">
                <input></input>
                <p class="id">7</p>
            </div>
            <div id="8" class="box">
                <input></input>
                <p class="id">8</p>
            </div>
            <div id="9" class="box">
                <input></input>
                <p class="id">9</p>
            </div>
            <div id="10" class="box">
                <input></input>
                <p class="id">10</p>
            </div>
            <div id="11" class="box">
                <input></input>
                <p class="id">11</p>
            </div>
            <div id="12" class="box">
                <input></input>
                <p class="id">12</p>
            </div>
            <div id="13" class="box">
                <input></input>
                <p class="id">13</p>
            </div>
            <div id="14" class="box">
                <input></input>
                <p class="id">14</p>
            </div>
            <div id="15" class="box">
              <input></input>
                <p class="id">15</p>
                <input></input>
            </div>
    </div>

如果模式更复杂,您还可以使用std::stringstream

input{
    outline: none;
    border: none;
    background-color: transparent;
    text-align: center;
    font-size: 40px;
    width: 80px;
    height: 80px;
    font-family: Verdana, Geneva, sans-serif;
    margin: 0;
}