Skip to main content
C++

String data type in C++

By January 4, 2020January 5th, 2020No Comments
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;
}

Leave a Reply