definition + integer confusion

I am attempting to make a for loop that will simultaneously count up ++ til eight, and also place the number at the end of a file access. Looks something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#define GAME "C:\\GAME\\"
#define DATA GAME "DATA\\"
#define SAVE DATA "SAVES\\"
#define dirnoexist "Directory Does Not Exist\n"
#define dirnoexistfile "Directory Does Not Exist, Identified as FILE.\n"



void newgame()
{
	string mx;
	string strPath;
	int ff = 0;//Confusion.
SetConsoleTitle("NEW GAME");

for (ff++; ff>0;) {
	ff++;
	string ORANGE = SAVE + ff;
    strPath = ORANGE + ".txt";
	cout << ff << endl;
cout << ORANGE << endl;
  cout << strPath;


 if (_access( strPath.c_str(), 0 ) == 0 ) //folder&|file check
     struct stat status;
     stat( strPath.c_str(), &status );
          if ( status.st_mode && S_IFDIR )
          {
       
		//good
          }

          else
          {
          cout << dirnoexistfile << endl; //folder is a file does not exists
		  cout << "Files are Corrupted.";
		  return;
          }

 }

  else
   {
cout << "Directory Does Not Exist" << endl; //folder does not exists
        
 }
 if (ff == 8)
 {
cout << "No Empty Game Slots, Overwrite a game?(Y/N)\n";//Display 8 Saves and 1-8 Select which game to overwrite
cin >> mx;
//cout << "Which Saved Game Would You Like To Overwrite\n";
 }
 else
 {

 }
}

}

This section is old code I couldn't find the correct for loop. But still, my problem is the file name, which shows up like:

2
\GAME\DATA\SAVES\
\GAME\DATA\SAVES\.txtDirectory Does Not Exist
3
GAME\DATA\SAVES\
GAME\DATA\SAVES\.txtDirectory Does Not Exist
4
AME\DATA\SAVES\
AME\DATA\SAVES\.txtDirectory Does Not Exist

instead of the integer being added onto the end, it seems to just be taking away memory? I have absolutely no clue on how to fix this, though I am sure the answer is easy enough. Any suggestions, comments, answers, corrections, links are always welcomed and thanked. If I am missing something for this code to run properly, also give me a heads up so I can assist you in assisting me.
The function "SetConsoleTitle(...)", Line 14, and a few other functions here require the inclusion of 'windows.h', you may have it already but I don't see it so it's worth mentioning.

The "for(...)" loop on Line 16 looks backward, you should double check that. Also Line 17 is useless or redundent.

The "if(...)" statement on Line 25 appears to be broken.

I haven't actually tried to compile you code since a lot of it is missing so I hope I was able to address the problem.
I already have the windows.h included at the very top. I fixed the for loop to look like
for (ff = 0;ff <= 8;ff++) {
the if statement works just fine when I use it.
I am still having the problem with the loop doing what I want it to do.

How can I get the integer to be placed within the string.
I want the program to get the string from
"C:\\GAME\\DATA\\SAVES\\"
to
"C:\\GAME\\DATA\\SAVES\\1"
to
"C:\\GAME\\DATA\\SAVES\\1.txt"
then loop back and change the integer
"C:\\GAME\\DATA\\SAVES\\2.txt"
"C:\\GAME\\DATA\\SAVES\\3.txt"
so on and so forth til it reaches
"C:\\GAME\\DATA\\SAVES\\8.txt"
How can I correctly do this?
Have you tried casting your variable "ff" to a stringstream?
So:

1
2
3
4
5
6
7
8
9
10
11
12
#include <sstream>

//...

std::stringstream ss;
std::string FF;

ss << ff;

ss >> FF; /*Notice this is to the new string NOT the integer you set up*/

string ORANGE = SAVE + FF; /*This alters what you have on Line 18 up above*/

Last edited on
I changed it to look like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
for (ff = 0;ff <= 8;ff++) {
	stringstream ss;
	string FF;

	ss << ff;
	FF >> ss;

	string ORANGE = SAVE + FF;

    strPath = ORANGE + ".txt";
	cout << ff << endl;
cout << ORANGE << endl;
  cout << strPath;



 if (_access( strPath.c_str(), 0 ) == 0 ) 
 {
     struct stat status;
     stat( strPath.c_str(), &status );
          if ( status.st_mode && S_IFDIR )
		  {
			  //*
        string line;
  ifstream myfile (strPath.c_str());
  if (myfile.is_open())
  {
    while ( myfile.good() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 

		  }
		  //*
		

          else
		  {
          cout << dirnoexistfile << endl; //folder is a file does not exists
		  cout << "Files are Corrupted.";
		  return;
          }

}

  else
  {
cout << "Directory Does Not Exist" << endl; //folder does not exists
        
 }
 if (ff == 8)
 {
cout << "No Empty Game Slots, Overwrite a game?(Y/N)\n";//Display 8 Saves and 1-8 Select which game to overwrite
cin >> mx;
cout << "Which Saved Game Would You Like To Overwrite\n";
 }
 else
 {

 }
}


all of the empty spots are things I haven't put in yet, I am so confused on this.
I ran it and I get 37 errors.
I'll try to post a separate post with all errors
Some of the errors.

c:\documents and settings\owner\desktop\xx\xx\xx.cpp(291) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
        c:\program files\microsoft visual studio 9.0\vc\include\iomanip(69) : see declaration of 'std::operator >>'
c:\documents and settings\owner\desktop\xx\xx\xx.cpp(291) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
        c:\program files\microsoft visual studio 9.0\vc\include\iomanip(69) : see declaration of 'std::operator >>'
c:\documents and settings\owner\desktop\xx\xx\xx.cpp(291) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
        c:\program files\microsoft visual studio 9.0\vc\include\iomanip(69) : see declaration of 'std::operator >>'
c:\documents and settings\owner\desktop\xx\xx\xx.cpp(291) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::string'
The FF >> ss; is kind of screwing it up some how.
Topic archived. No new replies allowed.