Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8331255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:21:34+00:00 2026-06-09T02:21:34+00:00

I am working on a save file system for a game, and trying to

  • 0

I am working on a save file system for a game, and trying to make sure I can get the file open in a small test program, determine whether it is empty, if it is empty prompt the user to create a character, and if its not empty load the character’s information into variables to be used for the game. So far in my testing I’ve created the files in notepad (leaving them empty), saved them with appropriate extensions, and attempted to open the file and test if they are empty.

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main ( int argc, char* argv[])
{
   struct charFile
   {
      int chapterNum;
      int savePoint;
      string firstName;
      char gender, hairColor, hairType, hairLength, eyeColor, profession, magic, martialSkills;
      bool hasPet;
   } character;

   fstream save;

   char saveFileChoice;
   string saveFile;

   cout << "Select a File (1, 2, 3, 4, 5, or 6): ";
   cin >> saveFileChoice;


   saveFile = saveFileChoice + ".charsav";

   save.open(saveFile.c_str());
   if (!save.good())
   {
      cout << "Save file cannot be opened.\n";
   }

   char tempStr[12];
   save.getline (tempStr, 256);
   if ( tempStr == "EMPTY" )
   {
      cout << "There is no save data in the file.  Starting a new game...\n\n";
      cout << "What is your character's name? ";
      cin >> character.firstName;
      save << character.firstName;

   }

return 0;
}

I was wondering why the file was never dropping into the if statement even though it was empty, and then even when I added EMPTY ascii characters to the file and changed the condition. Then I put in:

if (!save.good())
       {
          cout << "Save file cannot be opened.\n";
       }

and on running it constantly displays the message so for some reason the file isn’t opening. =/ I can’t figure out why though.

I’ve checked the files and they are not being formatted as .charsav.txt or anything, they are still just 1.charsav, 2.charsav, etc. I feel like I’m missing something easy and obvious. Can anybody point it out for me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:21:36+00:00Added an answer on June 9, 2026 at 2:21 am

    if (!strcmp(tempStr, “EMPTY” )) is how you compare strings

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to save an Assembly to a file using System.Reflection.Emit.AssemblyBuilder but it's
I save the form elements to a file and the following is working as
I'm working on a project in which a user can save their own coupon
I'm trying to use PHP to create a file, but it isn't working. I
How to save content of ArrayList to the file? I am working with the
I've been working on a text classification system and am trying to read words
Hi Im trying to create a file upload system where I am able to
I'm getting System.Data.SQLite.SQLiteException: Unable to open the database file. when I attempt to access
I'm trying to save a Java project in Eclipse as a jar file. As
I'm trying to rename a file after it's uploaded in the model's save method.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.