Hi,
im creating a simple class, that opens a text file, copies the text to a string and then prints it, i used a default argument, so it will opens pre-created file
but when i use my funcion print, it says "Expresion must have class type"
// text.cpp
#include "Text.h"
void Text::open_file(std::string file_name)
{
std::ifstream file(file_name);
std::string line;
while (getline(file, line))
text += line + "\n";
}
void Text::print()
{
std::cout << "In this file is written this:\n"
<< text << std::endl;
}
Text::Text(std::string file_name)
{
open_file(file_name);
}
Text::~Text()
{
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// source.cpp
#include <iostream>
#include "Text.h"
usingnamespace std;
int main()
{
Text test();
// test.print(); // Expresion must have class type
Text test2("text.txt");
test2.print(); // prints normally
cin.get();
}