【发布时间】:2017-06-13 05:12:45
【问题描述】:
我真的很想得到一些帮助来解决这个问题。 我有两个文件,一个 txt 文件和一个 xls 文件,在 txt 文件中它包含学生姓名及其 ID 的列表。在 xls 文件中,它包含字母和分配给它们的一些数字。 我需要为每个学生创建一个新的 txt 文件,以他们的 ID 作为文件名。在这个文件中,我需要显示分配给组成学生姓名的字母表的数字。请帮帮我,在txt filexls file给定的时间内实在搞不定
到目前为止,我使用 C++ 能够做的是从 txt 文件中读取数据,并将 xls 文件转换为 txt 文件并从中读取。我需要将数据存储在数组中还是更容易转换为结果文件
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream inputa("Students.txt");
ifstream inputb("Alphabet.txt");
if (!inputb.is_open()) std::cout << "Error: File Not Open" << '\n';
/* ofstream output;
output.open("output.txt");
This was just to see if it was getting anything
*/
string name;
string id;
string alphabet;
string number;
while (inputa >> name >> id || inputb >> alphabet >> number) {
/* here i planned to compare the strings using string::find, but it doesnt work */
}
system("pause");
return 0;
}
【问题讨论】:
-
如果您希望得到高质量的答案,您需要提供一个简单的示例和一些不起作用的代码。由于您已经弄清楚如何转换 xls 文件,请给出两个文件的内联示例、预期的输出文件以及您的代码不起作用或不完整。
-
感谢回复,我已经添加了
-
您还应该包含实际加载的转换后的 xls 文件(“Alphabet.txt”)。如果没有实际输入,就不可能给你准确的答案。乍一看,您应该首先将带有分配数字的整个字母表读入某种集合(可能是地图?)
-
感谢Kirsz的回复,我现在也添加了
标签: c++