How to use fstream to manipulate files

I need to write a program that reads a file and outputs it in another listed format. My teacher hasn't really went over the subject very well and I don't have much of an idea where to start. Here is the PreLab write up -

https://drive.google.com/file/d/0B82XiR3Hhx5HYVA4RjNBS1FOb28/view?usp=sharing

All the code I have is from cplusplus, I've tried learning how to do this but I've got no clue how to do it. The write up says we have to use the iomanip library but he hasn't even gone over what it is for yet so...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <iomanip>
using namespace std;
int main(int argc, char **argv);
  string line;
  ifstream myfile ("tc1");
  if (myfile.is_open())
  {
    while ( getline (myfile,line) )
    {
      cout << line << '\n';
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 

  return 0;
}
Last edited on
Line 7 has a ; instead of {

Check your compiler output. :)
Last edited on
Yeah, I just need to know how to format the output like the lab write up is saying, I just don't know how to do that.
Check out this page: http://www.cprogramming.com/tutorial/iomanip.html

If you need more help than what that page provides let me know but it should provide what you need to do.
Last edited on
Topic archived. No new replies allowed.