Teaching Newbies since 2014

  • Home
  • Javascript ❤
    • JavaScript
    • Node.js
  • WebDev Tuts
  • screencasts
  • Resources
  • VR & AR
  • Github
  • Twitter
  • YouTube
  • RSS
  • C++
You are here: Home / C++ / String data type in C++

January 4, 2020 by: Kauress

String data type in C++

I’m finding out that Udacity’s Nanodegree is missing small details. I do believe someone wrote the curriculum over breakfast in bed and hurried up because their coffee was getting cold or something. ANYWAYS. To use strings in C++, they must be included in your program as such:
#include <string>
using namespace std;
This is because strings:
  1. A class in C++
  2. Part of the standard library
This is similar to how in JavaScript, strings are also objects which is why you can access string properties such as length and use methods such as slice( ). Example:
#include <iostream>
#include <string>
using namespace std;

int main (){
string greeting = "Hello";
cout << greeting << "\n";
return 0;
}
Primitive Data Types in C++
Vectors in C++

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2022 ·Kauress

Go to mobile version