Tuesday, July 14, 2009

For C++ Programmers?

Can anyone tell me how to write a C++ program that appends data to the end of the file “abc.txt” ?





example program code is needed..


Thanks in advanced..

For C++ Programmers?
try opening the file in append mode . that is sa follows





FILE *fp;


fp = fopen("abc.txt","a");


// now write in the file whatever you wanted ,


// it will be appended ( a simple way)





//for writin a character


int putc(int ch , FILE *fp);


// now the charactrr pointed by "ch" will be appended





// or you can get the character from console as





do


{


ch=getchar();


putc(ch,fp);


}while(ch!= "$");








.........................


the easiest way is above :)
Reply:FILE* abcFile = fopen("abc.txt", "a");


fprintf( abcFile, "This is appended text\n");


fclose(abcFile);
Reply:#include %26lt;fstream%26gt;





...





ofstream outFile("abc.txt", ios::app);


outFile %26lt;%26lt; "I just appended this line" %26lt;%26lt; endl;


outFile.close();

salary survey

No comments:

Post a Comment