【发布时间】:2019-02-18 05:13:52
【问题描述】:
我在windows 7中使用VS2010编写C++ mfc程序。我想逐行读取一个txt文件并将其传递给字符串数组。
我尝试了 testByLine 函数,但它显示名称“fstream”未识别。此外,“ios::in”在我的 Windows 7 中似乎不正确,但我不知道如何更正。
#include "stdafx.h"
#include <fstream>
std::string Value_2[5];
void testByLine()
{
char buffer[256];
fstream outFile;
outFile.open("result.txt", ios::in);
int i = 0;
while (!outFile.eof()) {
outFile.getline(buffer, 128, '\n');
Value_2[i] = buffer;
i += 1;
}
outFile.close();
}
我希望 txt 中的每一行都被传递给字符串数组 Value_2 的每个元素。
【问题讨论】:
-
你在 fstream 前面少了
std::。 -
使用std::ifstream阅读
-
Your Rubber Duck 想聊聊
i不变的价值
标签: c++