
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Convert a C++ String to Upper Case
Here is the program to convert a string to uppercase in C++ language,
Example
#include<iostream> #include<string.h> using namespace std; int main() { char s[30] = "This_is_string"; int i; for(i=0;i<=strlen(s);i++) { if(s[i]>=97 && s[i]<=122) { s[i]=s[i]-32; } } cout<<"The String in Uppercase = "<<s; return 0; }
Output
Here is the output
The String in Uppercase = THIS_IS_STRING
In the program, the actual code of conversion of string to upper case is present in main() function. An array of char type s[30] is declared which stores the given string.
Then, for loop is used to convert the string into upper case string and if block is used to check that if characters are in lower case then, convert them in upper case by subtracting 32 from their ASCII value.
for(i=0;i<=strlen(s);i++) { if(s[i]>=97 && s[i]<=122) { s[i]=s[i]-32; } }
- Related Articles
- How to convert a string into upper case using JavaScript?
- How to convert Lower case to Upper Case using C#?
- How to convert Upper case to Lower Case using C#?
- C program to convert upper case to lower and vice versa by using string concepts
- C# program to count upper and lower case characters in a given string
- Convert characters of a string to opposite case in C++
- How to convert string to title case in C#?
- How to transform List string to upper case in Java?
- Program for converting Alternate characters of a string to Upper Case.\n
- PHP – Make an upper case string using mb_strtoupper()
- How to convert std::string to lower case in C++?
- Convert mixed case string to lower case in JavaScript
- How to check if a string contains only upper case letters in Python?
- Java program to count upper and lower case characters in a given string
- How to convert a string to camel case in JavaScript?

Advertisements