Hi! i am sorta new to this forum, but i have a problem with my code/compiler. i dont know if it is the compiler's fault or mine. I am self taught and learning from the book "SAMS teach yourself C++ in 21 days" i am trying to code a program that deletes(well, replaces the file with something else that has nothing in it.) other files. Here is my code...
Code:
#include <iostream>
#include <fstream>
using std::cin;
using std::endl;
using std::cout;
int main()
{
char filename[80];
while (true);
{
cout<<"Type '0' to exit the program"<<endl;
cout<<"Enter filename: ";
cin.getline();
if (filename[0]==0)
{
return 0;
}
ifstream fin(filename);
if (fin)
{
fin.close();
cout<<"Deleting"<<endl;
ofstream fout(filename,ios::trunc);
fout.close();
cout<<"Done!"<<endl;
continue;
}
cout<<"File not found!"<<endl;
}
cout<<"Error!!!"<<endl;
return 1;
}
Heres the errors i am getting and why i think i shouldn't get these errors, i am getting...
Code:
15 C:\Documents and Settings\Simon\My Documents\Untitled1.cpp no matching function for call to `std::basic_istream<char, std::char_traits<char> >::getline()'
but i know that the getline is being called from the #include <iostream> and also from the code using std::cin;
If i replace the code
getline(filename) with cin>>filename;
i have no problems from the compiler about the cin, but then again i get this error...
Code:
20 C:\Documents and Settings\Simon\My Documents\Untitled1.cpp `ifstream' undeclared (first use this function)
but i know i declared ifstream when i wrote #include <fstream>
i am using Dev-C++ 4.9.9.2 can someone here tell me if my logic is wrong or if my compiler is really buggy and need to get/download another one?