0

I have an assignment to output contents from a .txt file to html. I'm able to output the information from the .txt to the console but how would I output it into an html page? The txt and html files are in the same folder as my .cpp file.

#include <fstream>
#include <string>
#include <iostream>
using namespace std;

int main() {
    ofstream outFS;
    ifstream inFS;
    string inputFilename;
    string outputFilename;

    cout<<"Enter file name: " << endl;
    cin>>inputFilename;

    // Opens file
    inFS.open(inputFilename);

    // Check to see if file is in directory
    if (!inFS.is_open()) {
        cout<<"Could not open file " << inputFilename << endl;
        return 1;
    }

    // Reads each line of the file
    while (getline(inFS, inputFilename)) {
        cout<<inputFilename;
    }
    inFS.close();

}
4
Contributors
5
Replies
30
Views
3 Months
Discussion Span
Last Post by rproffitt
0

From what I understand of <fstream> is that ifstream is if you want to import contents from a file (which I did), and ofstream is when you want to outport contents to a file?

0

Yes that is what my comment shows. What may be confusing you is that you're using the variable inputFilename to hold each line from the file, instead of a separate variable. See if this clears it up:

string line = "";
outFS.open("OutputFile1.txt", std::ofstream::out)
// Reads each line of the file
while (getline(inFS, line)) 
{
    outFS << line;
}
outFS.close();
inFS.close();

Edited by tinstaafl

0

@امير_2
I have yet to find a C++ project with all functions. However you may be in luck as there is a C++ complier testing tool at https://embed.cs.utah.edu/csmith/using.html

That should create a set of projects that would have everything.

PS. You seem to have placed your new question in someone elses thread. Don't do that.

Edited by rproffitt: Clarifying

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.