I was messing around with toupper() because we just learned it in school and I wan't to change a whole word toupper so i look it up and got this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* toupper example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
int i=0;
char str[]="Test String.\n";
char c;
while (str[i])
{
c=str[i];
putchar (toupper(c));
i++;
}
return 0;
}
well I started messing around with it because I didn't understand putchar at first then figure that putchar is just like cout so I was messing around and made this program
The difference is obviously that you are coding to a different interface with each program which requires the inclusion of different header files. I lean more heavily towards using the C++ std template classes. The iostream template classes are fairly complex in and of themselves so if you try to mix the usage within one program you can really create a lot of unnecessary confusion for yourself. You can overload operator>> and operator<< for user defined types which allows you to write code that can directly interact with the streams in a very convenient and intuitive way. The cstdio functionality exists for forward compatibility (C to C++) I think. Nothing will stop you from using the c libraries if you want. however if you are an object oriented programmer you'll want to fully utilize those new mechanisms that are provided by the C++ template libraries.
This is a really difficult question for beginners to C++ because you may not fully understand the history of C++. When I took my first college class I used the cstdio library because that is what I was taught to do and I didn't know any better. After writing code for many years now I would never go back to using those libraries unless I had no choice. For instance if I am assigned to a project to maintain existing code that uses those libraries then I have to maintain a consistent programming style while maintaining that code. However if I am writing code for a brand new OO C++ project I will want to use the STL to the greatest extent possible.
Thanks for the information... I think I will be going lean more towards C++... But since i want to lean towards C++ more then C does that mean i shouldn't use <cctype> or <cmath> and stuff like that or is that OK?
Well cctype and cmath are just C++ includes for the C headers "type.h" and "math.h" respectively. I don't know why the standard is removing the .h suffix, maybe it's to avoid confusion with user created header files. Anyway, yes, it's fine to use them if you need them. AFAIK there isn't a math header specifically for C++ and there's no std::math.
One reason that you would need to convert strings to uppercase/lowercase one is that what if you ask the use to enter yes or no: but they enter Yes, yEs, or No, NO they are the same word right but in programming they are different so if you convert them down or up then you fix this problem.
Most of the programs I write use command line arguments, or take no user input. They just do a task, and print some output. But most of the programs I write are unusable; I write them just to learn.