View Full Version : printf itself
mickey
29th September 2007, 13:34
Hi,
I want to write a program that print its code. I saw the solution one time but it's wrong and I don't understand it. It's in C (but I use .Net compiler) (and if anyone know a solution in C++ or other language too, I'll happy).
See this....(don't ask me about char(38) please..I don't know).
How is the solution, please?
thanks..
Michiel
29th September 2007, 13:48
The Quine Page (http://www.nyx.net/~gthompso/quine.htm)
mickey
29th September 2007, 17:07
it seems that my iostream (.net2005) doens't contains method 'form' for cout (cout.form).
Is one other "C++" way to print? (apart printf). thanks.
Brandybuck
29th September 2007, 19:13
it seems that my iostream (.net2005) doens't contains method 'form' for cout (cout.form).
Is one other "C++" way to print? (apart printf). thanks.
I don't know any of this newfangled .NET stuff, but in C++ the standard way to print to standard output is with iostreams and the redirection operator.
cout << "Hello world!" << endl;
You can do the same with any other iostream derived object, including file streams.
mickey
29th September 2007, 20:08
I need a function C++ like printf to use char %c %s inside it.
cout.form was able to do this; But it seems vanished.
marcel
29th September 2007, 20:16
If you want your application to print its code, then the worst possible solution is the one you are using: store the code as a string in the actual code.
A better solution is to make the application store the code(by parsing the source files)in a separate module that will be distributed also. The module should preferably be encrypted, so only trusted users can see the code.
Michiel
29th September 2007, 20:41
That's cheating. ;)
wysota
29th September 2007, 20:45
What do you need it for anyway?
mickey
29th September 2007, 21:27
What do you need it for anyway?
here, http://www.nyx.net/~gthompso/self_c++.txt
as Michiel said, there is what I need. But as you can see there is the use of cout.form, and my compiler seems don't know it. I could use the printf but I'm looking for a pure c++ function where I can use %c %s characters....
wysota
29th September 2007, 21:37
But it doesn't say what you need it for :)
mickey
29th September 2007, 21:49
But it doesn't say what you need it for :)
I don't understand 'for': I need it to write a program that print its code. Have you see in the example link how cout.form is used? Is there a similar function that work as it?
wysota
29th September 2007, 22:03
I don't understand 'for': I need it to write a program that print its code.
Is it just for fun? For school? For any practical use? I'm just curious.
Is there a similar function that work as it?
try std::string and its sprintf method (I think it has one). Then you can redirect the result to cout.
mickey
29th September 2007, 22:47
OK!! It is just for fun. But I think your target in your question was another. Is it so? I'm curious too.....
But I don't find fprintf method in string; but if it's used to write on a file as said before it's a cheat...
wysota
29th September 2007, 23:14
OK!! It is just for fun. But I think your target in your question was another. Is it so? I'm curious too.....
No... I don't think so.
But I don't find fprintf method in string; but if it's used to write on a file as said before it's a cheat...
sprintf not fprintf. You sprintf what you want to printf into a string and then "printf" it (by redirecting) to cout :)
Something like:
std::string str;
str.sprintf("Format %s", "xyz");
std::cout << str << std::endl;
Just make sure std::string::sprintf really exists.
mickey
29th September 2007, 23:54
it doesn't exist as part of string....(at least in .net); but I wonder where's the "form" method....
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.