ok...let me restate my problem..
see this code snippet
//output to file
//no console output
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...
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.
you didn't get my question...i know how to output to file...but i wanted to ask is there any function which will open the file for user to see the output...
is there any showFile() type of function in libraries??
>I DONT know how to do that...
I'm willing to bet you do, but you're just not making the connection:
// Open a file and display it
void showFile ( const char *filename )
std::ifstream in ( filename );
while ( std::getline ( in, line ) )
std::cout<< line <<'\n';
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:
// 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() );
Then I guess the easiest, although not necessarily the best way, would be to call it from system.
using namespace std;
system("C:/test.xls"); //path to excel file
i tried it..and it is working absolutely fine...my code is
using namespace std;
for(int i=0 ; i<20 ; i++)
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?
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??