What's Here?
- Members: 137,226
- Replies: 481,486
- Topics: 75,059
- Snippets: 2,567
- Tutorials: 675
- Total Online: 2,078
- Members: 109
- Guests: 1,969
|
Creates a text file and writes custom or preexisting data to it.
|
Submitted By: KYA
|
|
|
Rating:
|
|
Views: 251 |
Language: C++
|
|
Last Modified: June 14, 2008 |
|
Instructions: Implement whenever custom data needs to be written unencrypted to a simple text file. Based on how you input it, you can simply "reverse" the process for retrieval. |
Snippet
/*
* Per request, this snippet shows how to create
* an empty file to write data to. Could
* be used to save game data or whatever inside a text
* file to be opened later
* KYA
* June 3,2008
*/
#include <iostream>
#include <string>
using namespace std;
int main()
{
FILE* newFile;
char name [256];
cout << "Enter data to be saved (string):";
fgets(name, 255, stdin); //collect input
newFile = fopen("gameSave.txt", "w"); //create file for writing
if (newFile == NULL){
cout << "Error creating new game save file";
}
else {
fputs(name, newFile); //writes data to file
fclose(newFile);
}
//Check directory for newly created file
}//end main
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|