| | |
how to open a file after running the program
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
@rajatC
your question is not clear. Do you want to redirct standered output?
You can use CreateFile API to open the file. However, keep this in mind, and make sure there is no sharing violation.
your question is not clear. Do you want to redirct standered output?
You can use CreateFile API to open the file. However, keep this in mind, and make sure there is no sharing violation.
Last edited by dubeyprateek; Dec 19th, 2007 at 3:26 pm.
I know I am. Therefore I am.
ok...let me restate my problem..
see this code snippet
see the second last line of my code... the output has been saved to output.txt.. no console output..
when i run the program the command window will blink...as i have not used
what i want to do with showFile function is that it will open the file output.txt so that user can see the file...
i hope now you got it...
see this code snippet
c++ Syntax (Toggle Plain Text)
int main() { ofstream fout("output.txt"); //processing. //output to file //using fout //no console output //showFile(output.txt); return 0; }
see the second last line of my code... the output has been saved to output.txt.. no console output..
when i run the program the command window will blink...as i have not used
system("pause") to retain it...what i want to do with showFile function is that it will open the file output.txt so that user can see the file...
i hope now you got it...
Last edited by rajatC; Dec 20th, 2007 at 3:31 am.
do it the same way as you would with cout to print to the console
fout << "Hello World\n"; . The syntax is identical to cout. Then close the file fout.close(); before calling your showFile() function so that everything gets physically written to the disk. Last edited by Ancient Dragon; Dec 20th, 2007 at 7:01 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
>I DONT know how to do that...
I'm willing to bet you do, but you're just not making the connection:
Though I'll go out on a limb and wager that you don't want console output, but rather you want to start some random text editor that will display the file for you. That's non-portable, but you might do something like this:
I'm willing to bet you do, but you're just not making the connection:
C++ Syntax (Toggle Plain Text)
#include <fstream> #include <string> // Open a file and display it void showFile ( const char *filename ) { std::ifstream in ( filename ); std::string line; while ( std::getline ( in, line ) ) std::cout<< line <<'\n'; }
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <string> // Open a file and display it in the specified program void showFile ( const std::string& program, const std::string& filename ) { std::system ( ( program + " " + filename ).c_str() ); }
I'm here to prove you wrong.
>Of course the user could always use Notepad to view the file.
Oddly enough, my test call for that function was:
Oddly enough, my test call for that function was:
C++ Syntax (Toggle Plain Text)
showFile ( "notepad.exe", "C:\\narue_is_kewl.txt" );
I'm here to prove you wrong.
![]() |
Similar Threads
- Can seem to open my file (C++)
- Button Click Opens new file/program (VB.NET)
- IE does not open *any* online web pages (Web Browsers)
- removed spyware now IE wont work (Viruses, Spyware and other Nasties)
- Another Program Launching mine (C++)
- can't open regedit (Viruses, Spyware and other Nasties)
- Can't open any programs (Viruses, Spyware and other Nasties)
- Nothing will open in my Internet explorer (Web Browsers)
- End program when logging off (Windows NT / 2000 / XP)
- file unable to open (C++)
Other Threads in the C++ Forum
- Previous Thread: adding & subtracting objects from a list
- Next Thread: Please advise
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






