字符串数组到多个字符串数组 [英] string array into multiple string arrays

查看:213
本文介绍了字符串数组到多个字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个字符串数组,用于保存从文件中读取的数据。它包含70行。



我想要做的是将它们存储在不同的数组中。比如从第21行到第31行的1阵列。第31至41个阵列。我该怎么办... plz help



我想将70行分成7个阵列,每个阵列包含10行。并且不使用向量

have a string array which keeps data which read from a file. it consists 70 lines.

what i want to do is store those in different arrays. like from 21st line to 31st line in 1 array. and 31st to 41st one array. how can i do it... plz help

i want to split 70 lines into 7 arrays each containing 10 lines of it. and do it without using vectors

推荐答案

类似的东西可能对你有用;



Something similar to this might work for you;

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main (int argc, const char* argv[])
{
    // Read the lines
    string lines[70];
    fstream file("C:\\Temp\\file.txt");
    string line;
    int index = 0;
    while(getline(file, line) && index < 70)
    {
        lines[index++] = line;
    }

    // Split the lines across arrays of ten lines each
    string splitLines[10][10];
    for(int i = 0; i < index; ++i)
        splitLines[i / 10][i % 10] = lines[i];

    return 0;
}





希望这会有所帮助,

Fredrik



Hope this helps,
Fredrik


这篇关于字符串数组到多个字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆