Is there an easier way to resolve this? Basically, can the original structure of the code in C be as similarly and closely translated into c++. I have not learned the std::transform.
The original code is valid C++. If anything, to write it exactly as it is in C++ you could do this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <cstdio>
#include <cctype>
int main ()
{
int i=0;
char str[]="Test String.\n";
char c;
while (str[i])
{
c=str[i];
putchar (toupper(c));
i++;
}
return 0;
}
However, C++ programmers should prefer the solution I posted above, due to being smaller and more intuitive as to its function. You should probably get used to learning the STL and the huge number of useful function that it provides. Only real way to fully learn it, though, is to spend time looking through the references that can be found, for example on this website.
@NT3, remember that touppper returns a number not a character. So you will need to explicitly cast the value returned, to a char in order to see the character.
So start learning now: http://en.cppreference.com/w/cpp/algorithm/transform
C++ standard library provides many useful functions you often had to write manually in C. It is good to know and use whatever your selected language can provide you with.