逐行读取文件,并将值存储到数组/字符串中? [英] Read file, line by line, and store values into a array/string?
本文介绍了逐行读取文件,并将值存储到数组/字符串中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
再次问好!我已经吸取了教训,所以我会做短暂的,并且对于小学。
我需要一个功能,在我班上,可以逐行读取文件,并将它们存储到数组/字符串中,以便我可以使用它。
我有以下示例(请不要笑,我是一个初学者):< br $> b $ b
Hello again! I have learned my lesson, so i will be short, and to the subiect.
I need a function, in my class, that can read a file line by line, and store them into a array/string so i can use it.
I have the following example( please don`t laugh, i am a begginer):
int CMYCLASS::LoadLines(std::string Filename)
{
std::ifstream input(Filename, std::ios::binary | ios::in);
input.seekg(0, ios::end);
char* title[1024];
input.read((char*)title, sizeof(int));
// here what ?? -_-
input.close();
for (int i = 0; i < sizeof(title); i++)
{
printf(" %.2X ";, title[i]);
}
printf("\");
return 0;
}
请帮助我!
Please help me!
推荐答案
CPlusPlus网站有很多有趣的教程代码,你应该阅读。这解释了文件输入和输出,还有一个文本示例。
The CPlusPlus website has a lot of interesting tutorial code which you should read. This explains file input and output and has also a text sample.
您想逐行阅读文本,那么为什么要将文件设置为二进制文件?你为什么要尝试将一个整数读入一个1024长度的字符串,从文件的末尾开始?我建议你再继续尝试一些示例C ++教程。
You want to read text line by line, so why do you set the file to read in binary? And why are you trying to read a single integer into a 1024 length character string, from beyond the end of the file? I suggest you go and try some sample C++ tutorials before proceeding further.
这篇关于逐行读取文件,并将值存储到数组/字符串中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文