Answers for "string c++"

C++
9

declaring strings c++

std::string str = "hello world"; 
char *str = "hello world";
char str[] = "hello world"; 
char str[11] = "hello world";
Posted by: Guest on October-19-2020
20

string in cpp

// Include the string library
#include <string>

// Create a string variable
string greeting = "Hello";
Posted by: Guest on October-01-2020
3

c++ string

#include <string>
#include <iostream>
#include <type_traits>
#include <cstring>

int main() {
  std::string str = "Hello, there";
  std::cout << std::boolalpha
  << str.capacity() << ", " << str.size() << ", " << std::strlen(str.data()) // 12, 12, 12
  << '\n' << std::is_same_v<std::string, std::basic_string<char>> // true
  << '\n' << str.front() + str.substr(1, 10) + str.back() // Hello there
  << '\n' << str[0] // H
  << '\n';
  
  str += "!"; 
  std::cout << str << '\n'; // Hello, there!
  str.erase(4, 4); // Hellhere!
  str.pop_back(); // Hellhere
  str.insert(4, " "); // Hell here
  std::cout << str << '\n'; // Hell here
  
}
Posted by: Guest on February-28-2021
4

how can make string value in cpp

#include <string>
string hello= "hello you thre :)";
Posted by: Guest on June-07-2020
2

indexing strings in c++

// string::operator[]
#include <iostream>
#include <string>

int main ()
{
  std::string str ("Test string");
  for (int i=0; i<str.length(); ++i)
  {
    std::cout << str[i];
  }
  return 0;
}
Posted by: Guest on July-20-2020
1

string c++

#include <string>
std::begin		| returns an iterator to the beginning of a container 
std::end		| returns an iterator to the end of a container 
std::size		| returns the length of string
std::to_string	| converts a number to string
std::stoi		| converts a string to a signed integer
std::getline 	| read data from an I/O stream into a string
std::swap  		| specializes the std::swap algorithm
std::empty 		| checks whether the container is empty
Posted by: Guest on June-05-2021

Browse Popular Code Answers by Language