Well, I've gotten a C thing to do, now I'm used to C++, and don't know what I can do in C++, which I can't do in C, so how to i make VS2008 C++ check for C errors and such stuff?
Printable View
Well, I've gotten a C thing to do, now I'm used to C++, and don't know what I can do in C++, which I can't do in C, so how to i make VS2008 C++ check for C errors and such stuff?
Just name your source files with .c, instead of .cpp, and VC++ will compile it as a C program.
Yeah, I tried that ;)
C is complicated D: move on to C++, I say!
So when you try to build your .c file, what error messages do you get?
oh it worked ;)
just that C has other complicated stuff, that C++ doesn't xP
Well, I wanna ask what stuff like '%2.2f' does o.O?
Ok, I think I figured it out, when used in printf, it sets how many numbers and decimals, correct?
Yep.
I thought you said it was difficult? How come you're guessing it all right then?
Well, 'cause I looked at the output and the numbers, and saw that they had something in common xP
But I do very well notice that C++ is easier ;)
This is not something specific to C. Format strings are probably the most convenient ways to describe complex formatting and exist in other languages too. Think how you'd need to chain complex manipulators with cout to achieve the same simple effect.Quote:
'%2.2f'
Also extremely useful when internationalizing programs: fragments of sentences as cout takes them may not be translateable, whereas format strings with place-holders for numeric values are. Although here positional arguments might be even better (not possible with C printf I think): e.g "Copied %1 files from %2" - the values of %1 and %2 might not naturally come in the same order in a foreign language but you'd be able to write: "ZZZ %2 djhs: %1"
printf is available in C++ (although it is often not recommended because of type unsafety - a variadic function works on arguments without really knowing their type beyond what the coder says in the format string). In a type-safe way it is also available as boost::format.
Format strings are recommended learning, I think.