well here is my code... and i will bold what is being defined as an error.
Code:
void MCreateFile()
{
ofstream File;
ifstream testFile;
string filename;
CLEARSCREEN;
cout<<"Please enter the filename: ";
cin>>filename;
if(testFile.open(filename.c_str()))
{
testFile.close();
int samefile;
cout<<"\nThere is a file at the current save location with the same name...";
cout<<"\n <1>Overwrite";
cout<<"\n <2>Rename Current File";
cout<<"\n <3>Quit";
cout<<"\n ->: ";
cin>>samefile;
switch(samefile)
{
case 1:
testFile.open(filename.c_str(), ios::trunc);
testFile.close();
break;
case 2:
filename.clear();
cout<<"\nNew File Name: ";
cin>>filename;
break;
case 3:
Quit();
break;
default:
cout<<"\nNot a valid entry!";
cout<<"\n ->: ";
}
}
if(!File.open(filename.c_str()));
{
cout<<"File could not be created!";
Quit();
}
}
here are my compiler errors....
Code:
73 C:\Dev-Cpp\My Stuff\C++\PhoneBook\PhoneBook4\definitions.h could not convert `(&testFile)->std::basic_ifstream<_CharT, _Traits>::open [with _CharT = char, _Traits = std::char_traits<char>]((&filename)->std::basic_string<_CharT, _Traits, _Alloc>::c_str [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](), (std::_Ios_Openmode)8u)' to `bool'
105 C:\Dev-Cpp\My Stuff\C++\PhoneBook\PhoneBook4\definitions.h could not convert `(&File)->std::basic_ofstream<_CharT, _Traits>::open [with _CharT = char, _Traits = std::char_traits<char>]((&filename)->std::basic_string<_CharT, _Traits, _Alloc>::c_str [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](), std::operator|((std::_Ios_Openmode)16u, (std::_Ios_Openmode)32u))' to `bool'
105 C:\Dev-Cpp\My Stuff\C++\PhoneBook\PhoneBook4\definitions.h in argument to unary !
i realize that when you have a filename, it has to be a const char* type. whats goin on?