how to open a file after running the program

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: how to open a file after running the program

 
0
  #11
Jan 6th, 2008
Originally Posted by Narue View Post
>Of course the user could always use Notepad to view the file.
Oddly enough, my test call for that function was:
  1. showFile ( "notepad.exe", "C:\\narue_is_kewl.txt" );
thanks for the help...all that you told me is working fine....

now i have another problem...i want to open file with some other programs...like MS word,MS excel etc...

so what should be the program name (eg notepad.exe) for them....how can i find the exact name for all the text reading programs in my laptop..(wordpad,MS excel,MS access,MS word etc..)
Life is about being happy...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: how to open a file after running the program

 
0
  #12
Jan 6th, 2008
Reading and writing stuff from MS Office is a lot more difficult.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: how to open a file after running the program

 
0
  #13
Jan 6th, 2008
yeah i know that....i am trying to learn that also..
here just tell me how to open a file in excel or word through program..
Life is about being happy...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: how to open a file after running the program

 
0
  #14
Jan 6th, 2008
So you just want to open it.

Then I guess the easiest, although not necessarily the best way, would be to call it from system.

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. system("C:/test.xls"); //path to excel file
  7. }
Last edited by iamthwee; Jan 6th, 2008 at 7:19 am.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: how to open a file after running the program

 
0
  #15
Jan 6th, 2008
Originally Posted by iamthwee View Post
So you just want to open it.

Then I guess the easiest, although not necessarily the best way, would be to call it from system.

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. system("C:/test.xls"); //path to excel file
  7. }
i tried it..and it is working absolutely fine...my code is
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. int main()
  5. {
  6. ofstream fout("excel.csv");
  7.  
  8. int a[20];
  9. for(int i=0 ; i<20 ; i++)
  10. {
  11. srand(i);
  12. a[i]=rand()%100;
  13. fout<<a[i]<<",";
  14. if(i==10)
  15. fout<<"\n";
  16. }
  17. fout.close();
  18. system(("excel.csv"));
  19. return 0;
  20. }

i know that excel files need to be saved in CSV format...(i learned it here in other thread) now as u can see that i have just mentioned the filename in system call...while you wrote the path of the file...
but my program is still working..the file is getting opened on running the program..but how?
my program is saved in F drive and i haven't mentioned the file path..but it is in the same folder where the program is saved...may be that's why it is working without filepath..please clearify!

and my other question is that it doesn't require the name of the program in which the file has to be opened..as Naure told me to write the name of the program (see older posts) for example notepad.exe ? So i think it opens the file in the default program attached to that particular format of file or extension..is it correct?
Life is about being happy...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: how to open a file after running the program

 
0
  #16
Jan 6th, 2008
Yeah, that sounds about right.

Btw your program is not generating random numbers properly.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: how to open a file after running the program

 
0
  #17
Jan 6th, 2008
Originally Posted by iamthwee View Post
Btw your program is not generating random numbers properly.
what do you mean by not properly?
are you talking about seed i ?? well i wrote this program just to learn about writing to excel and opening it...i used rand function to save myself from typing and initializing the array, nothing else.

I should have used the time seed instead to generate random numbers..
is it that what you want to say??
Life is about being happy...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,672
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: how to open a file after running the program

 
0
  #18
Jan 6th, 2008
suggestions:
1. move line 10 srand() up above the loop. It should only be called once within the lifetime of the program. most people call it like this: srand( time(0) );
2. why do you need the array?
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: how to open a file after running the program

 
0
  #19
Jan 6th, 2008
Originally Posted by Ancient Dragon View Post
suggestions:
2. why do you need the array?
hmm...correct i dont need array....
Life is about being happy...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 1714 | Replies: 18
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC