September 17th, 2004, 05:53 AM
I am writing a C++ program that uses the "ofstream" function. The output is a C++ file and in the output file I need to use char function.
But only one problem is that i can't add the qutation marks. Here is the code:
int main( )
char *nme = new char;
char exten = ".cpp";
cout<<"Name of the file:\n";
int fname = strcat(nme, exten);
a_file<<"int main( )\n";
a_file<<" char a = "
and that is how far i can get because it will not let me add quotation marks to the outputed file. If you can help me please do.Thanks
September 17th, 2004, 01:47 PM
You simply need to tell the compiler that what you want is the ascii character ' rather than that you are specifying a character:
The following small c program will demonstrate it to you:
a_file << "char a = \\'a\\';";
char string = "char a = \\'a\\';";
Hope that helped.
[ac@ezranet c]$ gcc test.c -o test
[ac@ezranet c]$ ./test
char a = 'a';
September 17th, 2004, 08:55 PM
how do i print an ascii value in C++?