remove() function help

i need help with this bit of code. compiling it gives me an error
1
2
3
4
5
6
string filename;
string directory = "c:\\profiledata\\";
cout << "Enter in filename you want to delete\n";
cin.ignore();//use this because getline skips
getline(cin, filename);
remove(directory + filename); //error on this line 
What is "remove"? This is not a standard C++ function.
Last edited on
http://www.cplusplus.com/reference/cstdio/remove/

And of course there's the tr2 version in <filesystem>, if one has a compiler that supports it. (Or one could use boost filesystem in the same way.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
#include <filesystem>

namespace fs = std::tr2::sys ;

int main()
{

    fs::path filepath = "C:\\ProfileData" ;

    std::cout << "What is the file you would like to remove?\n" ;

    std::string filename ;
    std::getline(std::cin, filename) ;

    filepath /= filename ;

    if ( !fs::exists(filepath) )
        std::cout << filepath << " does not exist.\n" ;
    else
        fs::remove(filepath) ;
}
Topic archived. No new replies allowed.