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();

}

Recommended Answers

All 5 Replies

basically open the ofstream object for output, then use it instead of cout(outFS<<inputFilename;).

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?

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();

hi,I want a C ++ project that includes all functions

@امير_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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.