Xcode I/0 File

Ok, i am running a Link List program and want to Save all the Data onto Files.

Thats fine. But i cant find the files any where in my Mac.. can someone tell me where do Xcode save files?


I just think i will go back to devCode.
What files?
closed account (zb0S216C)
Usually, any files created by your program are placed within the project folder structure of your program, unless you told it otherwise. Scan (look) your project folder structure for the files, and if they aren't there, look at your source code and see if you've specified a specific directory.

Wazzak
ok, I created a simple Input / output program...

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
#include <iostream>
#include <fstream>

using namespace std;
char MAX_PATH;
int main ()
{
    
char filename [MAX_PATH + 1];
    cout << "Enter a file name and press ENTER: ";
    cin.getline(filename, MAX_PATH);
    ofstream file_out(filename);
    if (! file_out) {
        cout << filename << " could not be opened.";
        cout << endl;
        system("PAUSE");
        return -1;
    }
    cout << filename << " was opened." << endl;
    file_out << "I read the" << endl;
    file_out << "news today," << endl;
    file_out << "ooh boy.";
    file_out.close();
    return 0;
}


And keep getting could not be opened while in the Terminal
even

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
#include <iostream>
#include <fstream>

using namespace std;
using std::ifstream;
using std::ofstream;
using std::endl;


int main ()
{
    ifstream instream;
    ofstream outstream;
    
    instream.open("infile.txt");
    outstream.open("outfile.txt");
    
    int first, second, thrid;
    
    instream >> first >> second >> thrid;
    outstream << "The Sum of the first 3\n"
              << "Numbers in infile.txt\n"
              << "is" << (first + second + thrid)
              << endl;
    
    instream.close();
    outstream.close();
    return 0;
    
}


This is not Creating a Text file.. is it me or is it just Xcode. I just installed Xcode 4.. thinking it easy to create Project not like NetBean for Ubuntu.
closed account (zb0S216C)
jackie wrote:
char MAX_PATH; (sic)

Not quite right. signed char has a range of -127:128 and unsigned char has a range of 0:255. char is signed by default. Not only that, it's not even initialized, so it could by anything. Also, C-Style arrays require a constant expression that can be resolved at compile-time for its length. Consider this line for MAX_PATH:

const unsigned int MAX_PATH( 256U );

Fix that minor issue and see what happens.

Wazzak
Last edited on
I can see where you coming from the char Max_Path..

but

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
#include <iostream>
#include <fstream>

using namespace std;
using std::ifstream;
using std::ofstream;
using std::endl;


int main ()
{
    ifstream instream;
    ofstream outstream;
    
    instream.open("infile.txt");
    outstream.open("outfile.txt");
    
    int first, second, thrid;
    
    instream >> first >> second >> thrid;
    outstream << "The Sum of the first 3\n"
              << "Numbers in infile.txt\n"
              << "is" << (first + second + thrid)
              << endl;
    
    instream.close();
    outstream.close();
    return 0;
    
}


This code is just a simple Create Text file and write into it.. but why isnt Xcode not Creating the txt file and if it is. its not in the Project folder.
closed account (zb0S216C)
Try running your program in release mode. Debug mode can cause some problems, such as the one you're experiencing.

Wazzak
outstream.open("outfile.txt"); The file will be created in the working directory (from where you executed the program)

Also http://cplusplus.com/reference/iostream/ofstream/is_open/
Try running your program in release mode. Debug mode can cause some problems, such as the one you're experiencing.


ok in Xcode how do i do that ?


working directory (from where you executed the program) the text files are not going to that.. that is the problem i am having i am creating a link list Programing for a home Data Base, but the Text files are not creating to test this

i done up a simple program and still have the same problem. I am new to Xcode i normally use Net Bean but it a pain trying work with

Last edited on
Topic archived. No new replies allowed.