Sharp Tutorial
string in C++

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

introduction to c++

  • C++ Home
  • Introduction to C++
  • History features
  • Sample Programs
  • cout , cin , endl
  • Data type and Operators
  • if else in c++
  • loop in c++

Oops in C++

  • Object / Class
  • Constructor
  • Function & Constructor Overloading
  • Inheritance
  • Overriding

Advanced C++

  • Strings in C++
  • Exception Handling
  • Special Functions
  • C++ Programs

string in c++

string used to store the value like name , address etc.

string variable is declared as  string name=”john”;.

C++ program to take input in string variable and print it back

#include<iostream>
using namespace std;
int main()
{
string course; cout<<"enter the course you want to learn"; cin>>course; cout<<"You Entered course= "<<course; return 0;
}

Important Functions on String in C++

1) length(): It gives the length of the given string.

string name="Sharp Tutorial";
cout<<name.length();

   Output: 14

2) concatenate two string: If we add two string it concatenate the strings into new resultant string.

string name1="Sharp";
string name2="Tutorial" string name=name1+name2;
cout<<"Full name="name;

   Output: Full name=SharpTutorial   [no space is added between these two strings]

3)  string at the given index: By using [index] we can get the string element at given index.

string name="Sharp";
cout<<name[1];

   Output: h  [ in the given string at index 1 ‘h’ is given.

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial