Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,380 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,192 people online right now. Registration is fast and FREE... Join Now!




Help with this error when checking for save text file.

 
Reply to this topicStart new topic

Help with this error when checking for save text file., error C2360: initialization of 'CheckSave' is skipped by '

Katyra
post 30 Aug, 2008 - 06:03 PM
Post #1


New D.I.C Head

*
Joined: 23 Aug, 2008
Posts: 5

Hey, I've been trying to make C++ read a text file where I save some information, and wanted to make it so that the option that would use the save.txt file (case 2) had a check function that checked that it actually was a text file with that name. But I don't know what is wrong here I get the errors:

error C2360: initialization of 'CheckSave' is skipped by 'case' label
error C2360: initialization of 'CheckSave' is skipped by 'case' label
error C2360: initialization of 'CheckSave' is skipped by 'default' label

what can I do?

CODE
bool CheckSaved()
{
    ofstream Save;
    Save.open ("Save.txt");
    if (Save.is_open())
    {
        return true;
    }
    else
    {
        return false;
    }
}

int IntroOptions()
{
    int IntroNum;
    cin        >> IntroNum;

    switch (IntroNum)
    {
        case 1:
            SaveCreation();
            break;
        case 2:
            bool CheckSave = CheckSaved();
        if(CheckSave == true){
            something();
        }
        else{
            somethingelse();
        }
            break;
        case 3:
            Credits();
            IntroOptions();
            break;    
        case 4:
            exit(1);
            break;
        default:
            cout << "Please press 1,2,3 or 4!\n";
            IntroOptions();
            break;
    }
    return 0;
}
User is offlineProfile CardPM

Go to the top of the page

JackOfAllTrades
post 30 Aug, 2008 - 07:38 PM
Post #2


D.I.C Addict

Group Icon
Joined: 23 Aug, 2008
Posts: 502



Thanked 44 times

Dream Kudos: 25
My Contributions


Wrap the contents in case 2 with {}, except for the break.
cpp
case 2:
{
bool CheckSave = CheckSaved();
if(CheckSave == true){
something();
}
else{
somethingelse();
}
}
break;
case 3:
User is offlineProfile CardPM

Go to the top of the page

Katyra
post 31 Aug, 2008 - 02:29 AM
Post #3


New D.I.C Head

*
Joined: 23 Aug, 2008
Posts: 5

Ah, ok. Thanks alot wink2.gif
User is offlineProfile CardPM

Go to the top of the page

Katyra
post 31 Aug, 2008 - 04:26 AM
Post #4


New D.I.C Head

*
Joined: 23 Aug, 2008
Posts: 5

Now I've tried to run it and I noticed that :
Save.open ("Save.txt");
made a file called Save.txt, I thought it would just open it if it existed. So it doesn't work very well to check if the file is there. How could I do this? :S
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 06:22AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month