//This programm is for testing function overloading
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
class Text
    {
    string str;
    public:
    Text ();
    Text (string);
    string contents ();
    };
Text::Text (string st)
    {
    ifstream in (st);
    getline (in, str);
    }
string Text::contents ()
    {
    string ret;
    ret=str;
    return ret;
    }
int main()
    {
    Text txt ("Sample.cpp");
    string stg;
    stg=txt.contents();
    cout << "The output of the file is" << "\n" << stg;
    }

Recommended Answers

All 2 Replies

I am getting error on line 16. Is there anything wrong?

Try this out.

ifstream in (st.c_str()

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.