//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

Try this out.

ifstream in (st.c_str()

Jump to Post

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.