Reputation: 23
I'm trying to create a simple text editor. I need to use the void functions as they are listed. I cannot change the parameters. I am able to call the first void function open(file) but not the insert command. I tested the open function by printing the struct with an overloaded operator.
int main()
{
editor_file file;
string command;
string insert;
cout << "Welcome to TextEditor. Please enter a filename: ";
open(file);
cout << file;
cout << '>';
cin >> command;
if(command == insert)
{
insert(file); // error: no match for call to '(std::string) (editor_file&)'
}
cout << file;
return 0;
}
void functions in separate file
void open(editor_file &file)
{
string line;
string filename;
ifstream fin(filename.c_str());
do
{
cin >> filename;
fin.open(filename.c_str());
file.name = filename;
if(fin.fail())
{
cout << "Invalid File. ";
cout << "Please enter another file name: ";
}
}while (fin.fail());
getline(fin, line);
while(fin)
{
file.data += line + '\n';
getline(fin, line);
}
}
void insert(editor_file &file)
{
char character;
cin >> character;
string info = file.data;
info.insert(file.cursor, character);
}
struct in header file
struct editor_file
{
std::string name;
std::string data;
int cursor;
bool is_open;
bool is_saved;
editor_file():cursor(0),is_open(false), is_saved(true) {}
};
Upvotes: 2
Views: 2191
Reputation: 41092
Try to rename your
string insert
To something like
string strInsert
This is because you shouldn't use the same name for both a variable and a function!
Upvotes: 3