http://www.cplusplus.com/doc/tutorial/files/
I just finished executing this but I didn't get any file on my desktop.
So where does the .txt file get placed on my computer?
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
Damn... I've seen this post never answered many times..
Here's the solution
In your project navigator when you're working in your current project there are many files. Try products (if I remember) and look for the executable file. Now go to the properties inspector or whatever is called. (Right side of your Xcode.)
There you will find somewhere a part called PATH the path that is written over there. It's the path where the executable runs. That means there is where you'll find all the files you create with your program.
Try it... that's how I manage and look my .txt files since sometimes I wanna give them some kind of formatting.
I hope I've solved your problem... cheers! ;)
Click on the executable in the Products tab on the left hand side, and you should see the path to it displayed on the right in the utilities section. This is where they are saved. On my computer this path is:
/Users/myName/Library/Developer/Xcode/DerivedData/CurrentXcodeProject-adsnvetbleazktcgitfymfcbhkkt/Build/Products/Debug/filename.txt
In the "current directory", meaning the working directory of the environment from which you ran the executable.
I can't tell you what that is, but in basic cases it may be the directory where the executable is located. In many other cases it may not be.
Performing a search for the file on your hard drive will reveal its location to you.
Right click on your product and select "Show in Finder". Thats opens the path to where the output files go. Also you can add input files there to be read in by your program.
Found best answer here:
File creation in C++ on Xcode
Basically you can specify a known directory so that all files created go there.
If you are on Mavericks Right click in your user folder with your documents and pictures and stuff (~/Users/yourusername)
Now right click and view options. Check "show library". Now follow to the path that the first user above said.
What I've always done when an application saves a file and I don't know where... is just go back to that application, and hit File>Save As...
So re-open Xcode and go to the "File" menu, and click "Save As..."
It will show you the same directory it just saved to.
I have checked the "Current Directory" but I believe I have to specify the location. Not even
~User/Desktop
will work.
What I do is create an empty file with a the correct name on my desktop then drag that file into my Xcode project to get its path. I then delete the file.
Same with adding files to my project. I can add them from the File menu, but I will need to drag them in to the spot in my code where I want to reference them.
It is kind of convoluted but it is the only system I have.
Some of the answers are confusing. Here's the simplest solution.
1. Expand your Products folder on the left-hand side
2. Right click on the terminal icon(sorry I do not know what it's called)
3. Click show in Finder.
You should be able to see your output file in there.
" Where does Xcode create .txt files to? "
You can decide where you want: follow these->
" Product->Scheme->EditScheme "
chose options tab in the new popup "options"
"working directory" tick "use coatroom working directory" and locate the folder where you want.
The .txt file that you "create", or that you want too "read" has to keep in this folder.
In 2022, click on the project name in the "breadcrumbs" area above the editor. Select the correct thing in "Products", then in the right area, see "Full Path".
Related
my notepad++ cpp is file shows an internet explorer sign as it is being saved, opens in internet explorer or I have not choose which software I want to use to open it, instead of just opening in notepadd++, but when ever I try to see the info about file it shows cpp I looked up and didn't find any such question to get answer from.
Maybe it's being saved with the wrong ending. are you hiding file extensions in explorer? Right click on the file and check the name in properties. Also you want to ensure that file extensions are always shown. Go into "view" in Windows Explorer and ensure that "file extensions" checkbox is on (later Windows versions). Or in earlier Windows/Windows in general, click into Folder Options/View and turn off "Hide Extensions for known files". As a developer you always want file extensions shown.
If you have the wrote file extension and it's hidden the file could be like "file.cpp.txt" or "file.cpp.html" or something instead of an actual cpp file.
Once you've double-checked the file extension and made sure file extensions are not hidden, if that isn't it, right click the desired file and look at "Open With", "Choose Another App/Program" (depending on Windows version), then look for the right program to open it with and make sure you click "always open with this program".
My Eclipse didn't show any console outputs.
I tested the ".exe" in the debug file of my C++ project, with wich i received an error that "libgcc_s_dw2-1.dll" was missing.
I read abit on this and i found that i could simply copy/paste that file from my c:/MinGW/bin folder to the ".exe" in the "/debug" folder of my project.
That helped me with that error but i then received the message that "libstdc++-6.dll" was missing, so i did the same again.
Now The ".exe" works fine and I get an output in my eclipse.
But now i'm afraid that i will get simillar erro's at my next build if i use some what more complex programming.
I also think that it would be very timeconsuming if i have to add those files too all of my future projects.
Question:
So my question now isn't there a way to tell eclpise that those .dll files are at "c:/MinGW/bin"?
PS.
I suspect that a similar question already exists but I wouldn't have a clue on what tags I'd have to search for.
Speacial thanks to #Deniz !
right click on "my computer" => properties .
on the right select "Advanced system settings".
open "Enviormentvariables"
search for "path"
select Edit
you'll have a list of paths, hit "end" on your keyboard to make sure you are at the end of this list.
then add ";" to close the previous path and add the path to your MinGW/bin location. (by default C:\MinGW\bin).
result in adding ";C:\MinGW\bin"
I'm trying to learn some DirectX11 and I found good tutorial I'm following; however, for some reason the program crashes (The window appears but then a "not responding" message box appears), even though the build was successful. There were some thing about creating shader-files the author did specify on how to do, and i wanted to make sure I'm not making any errors there and that why my program crashes. So my questions are :
How do you create a shader files? In the tutorial we are using the extension .fx, but when you add a file in vs you can only choose from .h and .cpp . Do you only have to select .cpp and then add .fx in the end of the file name?
In what directory is the file suppose to be? (My files are currently in Source Files)
Yes that will work. Another way to do it is just to create a .txt then change the extention to .fx
(To show the file extention just open any folder, click on the organize button in the menu then choose "folder and search options". Uncheck the box "Hide extentions for know file types" under the tab view). After you change the extention you can open the document in notepad and write your code there
Go in to your project folder (in windows file system) and create a map called Data. Add you .fx file there. Then go to your solution explorer and rigth click on the project and choose properties. Go to Build Events -> Pre- Build Events. Add the line "xcopy /y /d "$(ProjectDir)Data" "$(OutDir)" in the box "Command Line". Now when building your project the files will be copied to the rigth place and you will be able to use your .fx file.
The .fx is associate it with an effect file. Meaning you have a combination of many shaders in the same file. Can you post some code of your render loop... also, are you calling the Present method?i.e.,
m_pSwapChain->Present(0, 0);
I'm trying to write a few algorithm programs practising for Google Code Jam but I can't get XCode to read from an input file (easily).
I have added the file to the project and it appears in the left hand file navigation bar. But I can't reference it relatively. In Code::Blocks I just input from "FileName.txt" and it works but with XCode it just can't find it.
If I put the full file path (i.e. /Users/myname/Documents/Google Code Jam/ProjectName/ProjectName/FileName.txt) then it works but that just seems ridiculous.
Is there anything I can do to get XCode to work? When I added the file I ticked the copy file into project directory and also the add to target executable.
Any help is appreciated.
Thanks!
I just found this and the comments by Julio Gorgé is just what I needed. The default working directory when running in debug mode is some esoteric folder (as you can see in iOS if you include system("pwd"); at the beginning of your main().
It's in the "Options" tab of the Edit Scheme... menu that you can tick "Use custom working directory" and find the test file you put in in the Arguments tab.
alt text http://img638.imageshack.us/img638/5731/screenshot20100613at121.png
Why does the c++ program produce the error shown? I'm especially confused since outfile opens without error yet infile displays the error? Both are defined in xcode exactly the same!! I've altering the "path type" setting without success. The open on infile always fails! Any suggestions would be very much appreciated!!
For those who responded thanks but as you can see but infile and outfile exist and are in the same location:
alt text http://img709.imageshack.us/img709/9316/screenshot20100613at123.png
In Xcode, expand the "Targets" node and find your target. Given what I've seen, it'll be the only one there.
Next, right-click on your project and add a new "Copy Files" build phase. When the dialog box comes up, make sure you set the Destination to "Products Directory".
The new build phase will appear beneath your target with whatever name you gave it. Drag your in_file and out_file there.
Compile and run.
In your current case out_file would be created even if it doesn't exist (because you're using std::ofstream).
in_file, on the other hand, has to exist, and (I guess there is no such file in the directory with created binary), hence an error is produced.
Did you try launching your compiled application with the file in the same folder where the binary file is?
Probably there is no file named "in_file" in the program's working directory, so it can't be opened for reading.
For outfile this doesn't matter since it is opened for writing and if it doesn't exist yet it will just be created.
The directory listing you posted doesn't show where the compiled executable is, but probably it will be somewhere in the build directory. Probably this is then also its working directory and the place where the input file would need to be. (Look for the out_file the program creates when it is run, it will be created in the working directory, the same directory where it searches for in_file. And it is not the directory you posted the listing of, the out_file there is too old.)
Turns out you have to specifically create the file here:
Project Path/build/Debug
apparently you can't just define it directly in the xcode project