我試圖從單個文件中提取信息,並使用一條信息(在此參考文獻中,它將成爲某人的主要信息)我想將這些信息導向四個其他文件(根據專業)。對不起,如果這可能對你很明顯,但我真的很喜歡這個。這是我到目前爲止:如何從一個文件中提取信息並將信息分割爲四個其他文件?
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
double studNum;
float GPA;
string nameL;
string nameF;
char initM;
char majorCode;
ifstream inCisDegree;
ofstream outAppmajor;
ofstream outNetmajor;
ofstream outProgmajor;
ofstream outWebmajor;
inCisDegree.open("cisdegree.txt");
if (inCisDegree.fail())
{
cout << "Error opening input file.\n";
exit(1);
}
outAppmajor.open("appmajors.txt");
outNetmajor.open("netmajors.txt");
outProgmajor.open("progmajors.txt");
outWebmajor.open("webmajors.txt");
while (inCisDegree >> studNum >> GPA >> nameL >> nameF >> initM >> GPA >> majorCode);
inCisDegree >> studNum >> nameL >> nameF >> initM >> GPA >> majorCode;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
這基本上就我得到。我還有一點點,但只是讓我看看它是否有效。似乎studNum(文件中的學號)確實能夠工作,但是,其他一切似乎都無法正常工作。在確定如何正確地將信息放入四個文件之一中時,我也遇到了一些問題。謝謝你的幫助。我一直在努力工作幾個小時,但我的想法一直在空白。
編輯:在輸入文件中的信息是這樣的:10168822湯普森瑪莎W¯¯3.15
翻譯爲:studNum,NAMEL,NAMEF,initM,GPA,majorCode