Tuesday, July 14, 2009

How do I build a C++ program that produces a .txt file?

I'm a beginning programmer and I've made a few simple programs that deal with numbers but I wanted to develop a program that is just a simple word processing program with no GUI but just DOS. I know how to accept all of the typed text but creating a filename and allowing someone to choose were to save it is what I need help with. Please give me a hand. Thanks.

How do I build a C++ program that produces a .txt file?
http://www.cplusplus.com/doc/tutorial/fi...
Reply:very simple with c++





you need variable type FILE *


FILE *file; char string[]="hello";


file=fopen("whatever.txt","w");


fprintf(file,"%s world",string);


fclose(file);





look up fread and if u want, fwrite, theres plenty of functions for file input output but all i ever use is


fopen, fclose, fprintf, fread, and fwrite





the second parameter of fopen specifies the mode, the modes i am familiar with are r, w, a, ab, rb, and wb


whether or not the b is present specifies binary or not, if it is binary, special character conversions will not be performed, if not binary, it is text





r means read, w means write, a means append, basically self explanatory
Reply:c++


here is your hand


: im clapping


c++ is mind boggling


No comments:

Post a Comment