Answers for "cpp string functions"

C++
2

string function in c++?

// let's I want to make a string of same char with specific length
// I can use string something like this
string(length,charecter);
//length - is the length of string we want;
//charecter - the charecter that we want;
// example if string(5,'a') --> 'aaaaa'
//if string(3,'g') --> 'ggg'
Posted by: Guest on November-01-2021
3

string in cpp

// you want to include <string>
#include <string>
#include <iostream>

int main() 
{
  string helloWorld = "Hello World!"; // creating string and assigning
  std::cout << helloWorld;            // will output what you assigned it!
                                      /* you can also use strings with user 
                                      input (cin/getline)*/
  string namePerson{};
  getline(cin, namePerson); // getline allows for multi word input
  std::cout << namePerson;  // outputs name which person inputted
}
Posted by: Guest on October-20-2020

Browse Popular Code Answers by Language