Nov 30, 2015 at 6:41pm UTC
Hello, I have been stuck on this for a while.
I have the following .txt file as shown:
// ID Name Address St Zip Majr Minr
135792468 Wayne,John Duke 101 Hollywood Way CA 40815 CS MATH
I am trying to output create an output file that will print the following:
NAME: Wayne,John Duke
ADDRESS: 101 Hollywood Way, CA 40815
----------------------------------------------------------------------
Student ID: 135792468
Department: CS
Major: CS
Minor: MATH
So far my code is:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
//declare files
ifstream fin1;
ifstream fin2;
ofstream fout;
//open files, create transcript file
fin1.open("student_01.txt");
fin2.open("courses_01.txt");
fout.open("transcript_01.txt");
//print name
const int MAX = 21; //Number of chars in string
char name[MAX];
cin.getline( name, MAX );
fout << name << endl;
However, this is not working as I cannot get the name to output.
Any help or advice would be greatly appreciated, thank you.
Dec 1, 2015 at 11:30am UTC
you want to write this into a file ..
1 2
NAME: Wayne,John Duke
ADDRESS: 101 Hollywood Way, CA 40815
then why you are using three files .
open file1 for reading (file which has data)
read the each line in the file
if the line contains the data what you expecting
then write the data to another file
close the files .
Last edited on Dec 1, 2015 at 11:59am UTC
Dec 1, 2015 at 4:20pm UTC
The other file2 is for another part of the program.
I see what you mean but I'm confused on how exactly to read the files?
I tried to use .getline but it outputs the wrong line and it outputs the entire line.