file-io
Deleting a file in VBA
.) Check here. Basically do this: I’ll leave it to you to figure out the various error handling needed but these are among the error handling things I’d be considering: Check for an empty string being passed. Check for a string containing characters illegal in a file name/path 2.) How To Delete a File. Look at this. Basically … Read more
Java and Windows – error: illegal escape character
You need to escape the backslashes used in your path.
C++: Using ifstream with getline();
According to the C++ reference (here) getline sets the ios::fail when count-1 characters have been extracted. You would have to call filein.clear(); in between the getline() calls.
How to open a file for both reading and writing?
Here’s how you read a file, and then write to it (overwriting any existing data), without closing and reopening:
Copy a file in a sane, safe and efficient way
Copy a file in a sane way: This is so simple and intuitive to read it is worth the extra cost. If we were doing it a lot, better to fall back on OS calls to the file system. I am sure boost has a copy file method in its filesystem class. There is a C method … Read more
Read data from a file into an array – C++
The issue is that you’re declaring a local grades array with a size of 1, hiding the global grades array. Not only that, you are now accessing the array beyond the bounds, since the local grades array can only hold 1 item. So get rid of the line: However, it needs to be mentioned that this: is not valid C++ syntax. … Read more
UnicodeDecodeError: ‘charmap’ codec can’t decode byte X in position Y: character maps to
The file in question is not using the CP1252 encoding. It’s using another encoding. Which one you have to figure out yourself. Common ones are Latin-1 and UTF-8. Since 0x90 doesn’t actually mean anything in Latin-1, UTF-8 (where 0x90 is a continuation byte) is more likely. You specify the encoding when you open the file:
Read whole ASCII file into C++ std::string
There are a couple of possibilities. One I like uses a stringstream as a go-between: Now the contents of “file.txt” are available in a string as buffer.str(). Another possibility (though I certainly don’t like it as well) is much more like your original: Officially, this isn’t required to work under the C++98 or 03 standard (string … Read more
C read file line by line
If your task is not to invent the line-by-line reading function, but just to read the file line-by-line, you may use a typical code snippet involving the getline() function (see the manual page here):