| ekolet (11) | |
|
First I want to open a text file and save some data in it. 1)ofstream out; out.open("C:\\output1.txt"); <= this does not work, it works fine if i try to open a file under visual basic documents(out.open(output1.txt)) but cant open from another directory. Says it cannot be found. Than I want to read that file later in my program but I cannot save that file under C:\ so have to open it from C:\Users\W7\Documents\Visual Studio 2010\Projects\proj\proj\output.text but this So I use system("C:\\Users\\W7\\Documents\\Visual Studio 2010|\Projects\\proj\\proj\\output.text); But this does not work eighter because command window does not understand spaces between Visual studio so it tries to call "C:\\Users\\W7\\Documents\\Visual only. Any ideas how can i fix this? | |
|
|
|
| Peter87 (3917) | |
| You probably don't have permission to write to files in C:\. Why use system? Can't you use pass the path to ofstream? | |
|
|
|
| Darkmaster (494) | |
|
you dont have the right do write there. you could try to run your exe as an admin. | |
|
|
|
| ekolet (11) | |
|
I have to use system because what i do is, randomly create some data on a text file, open dos console, call a 3rd party exe file along with my text file than redirect the output in dos console into another text file. I am reading from dos console not from a text file. How can I gain access to write in C:? I am running my code through compiler not as an exe file. | |
|
|
|
| ekolet (11) | |
|
ofstream out; out.open("C:\\output9.txt"); I compiled this to see if it creates a file called output9 and started it as an administrator. It did not work. | |
|
|
|
| ekolet (11) | |
| No it didnt nvm lol | |
|
Last edited on
|
|
| Peter87 (3917) | |
| I think you can use spaces in paths in system if you put the path inside quotes. | |
|
|
|
| ekolet (11) | |
|
Well i think it makes sense but i cant. | |
|
|
|
| ekolet (11) | |
|
I am literally going to smash my keyboard into my screen. I am trying to open a goddamn file for last 4 days and cannot believe such a simple operation giving me such a headache. | |
|
|
|
| Darkmaster (494) | |
| maybe the boost library can help you out | |
|
|
|
| Athar (4466) | |||
How?
Of course you can. You need to escape quotation marks inside a string: \" | |||
|
|
|||
| andywestken (1966) | ||||||
Usually, apps write temporary files to the temp folder, not the system root. Windows will tell you the path to temp if you call GetTempPath (it's returned as a short path, i.e. long files names are converted to 8.3 names) GetTempPath function (Windows) http://msdn.microsoft.com/en-gb/library/windows/desktop/aa364992%28v=vs.85%29.aspx And it's good manners to create a subfolder in the temp folder and write your files there. And easy to find them for debugging purposes. (stick %temp% into Windows Explorer address bar, Start/Run %temp%, or cd %temp% from command line). Andy PS Mis-using system to list the .cpp files in a folder. The app needs to be run from a folder containing .cpp files. If successful, then notepad should open to display a list of .cpp files.
With short names:
With long names:
| ||||||
|
Last edited on
|
||||||
| Stewbond (1843) | |
If you have problems with the following because it contains spaces:system("C:\\Users\\W7\\Documents\\Visual Studio 2010|\Projects\\proj\\proj\\output.text); Then use this instead: system("\"C:\\Users\\W7\\Documents\\Visual Studio 2010\\Projects\\proj\\proj\\output.text\"");
| |
|
Last edited on
|
|
| modoran (1245) | |
| I think ShellExecute() could be much better choice if you want to execute the program associated with .txt extension, as system() does in that example. | |
|
|
|