字符串数组到多个字符串数组

编程入门 行业动态 更新时间:2024-10-24 18:27:20
本文介绍了字符串数组到多个字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有一个字符串数组,用于保存从文件中读取的数据。它包含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

更多推荐

字符串数组到多个字符串数组

本文发布于:2023-08-07 13:55:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319421.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字符串   多个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!