##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::remove

From cppreference.com
< cpp‎ | io‎ | c

Defined in header `<cstdio>` |  |
int remove( const char *fname ); |  |

Deletes the file identified by character string pointed to by `fname`.

### [edit] Parameters

fname | - | pointer to a null-terminated string containing the path identifying the file to delete

### [edit] Return value

​0​ upon success or non-zero value on error.

### [edit] Notes

In POSIX the behavior for file types other than regular files is unspecified.

### [edit] Example

Run this code

    #include <cstdio>
    #include <iostream>

    int main()
    {
        const char* file_name = "C:\\file.txt";
        int ret_code = std::remove(file_name);
        if (ret_code == 0) {
            std::cout << "File was successfully deleted\n";
        } else {
            std::cerr << "Error during the deletion: " << ret_code << '\n';
        }
    }

Possible output:

    Error during the deletion: 1

### [edit] See also

rename | renames a file (function) [edit]
C documentation for remove

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/c/remove&oldid=64919"