Answers for "c++ string manipulation"

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
11

c++ string

#include <string>

std::string myString = "Hello, World!";
Posted by: Guest on May-16-2020
1

c++ string manipulation

/*
OUTPUT
String value: Programming    {where applicable: -31.05}
-----------------------------------------------------------------------------
|Programming|            << [No manipulation]
|         Programming|   << [Width:20][align:string_default=right]
|         Programming|   << [Width:20][align:right]
|Programming         |   << [Width:20][align:left]
|-31.05              |   << [Width:20][align:int_default=left]
|-              31.05|   << [Width:20][align:internal]
|.........Programming|   << [Width:20][align:default][fill:.]
|+++++++++Programming|   << [Width:20][align:default][fill:+]
|=========Programming|   << [Width:20][align:default][fill:=]
-----------------------------------------------------------------------------
*/

string sString = "Programming"; // Length = 11 
//NOTE: always place the settings before the actual string in cout

// width
cout << "|" << sString << "|" << "\t\t << [No manipulation]" << endl;
cout << "|" << setw(20) << sString << "|" << "\t << [Width:20][align:string_default=right]\n";

// alignment
cout << "|" << setw(20) << right << sString << "|" << "\t << [Width:20][align:right]\n";
cout << "|" << setw(20) << left << sString << "|" << "\t << [Width:20][align:left]\n";
cout << "|" << setw(20) << -31.05 << "|" << "\t << [Width:20][align:int_default=left]\n";
cout << "|" << setw(20) << internal << -31.05 << "|" << "\t << [Width:20][align:internal]\n";

// fill (HAVE to use single quotes in the setfill argument definition)
cout << "|" << setw(20) << setfill('.') << sString << "|" << "\t << [Width:20][align:default][fill:.]\n";
cout << "|" << setw(20) << setfill('+') << sString << "|" << "\t << [Width:20][align:default][fill:+]\n";
cout << "|" << setw(20) << setfill('=') << sString << "|" << "\t << [Width:20][align:default][fill:=]\n";
Posted by: Guest on June-02-2020
0

c++ write string

#include <iostream>

int main() {
	std::cout << "Hello" << std::endl; //endl = end line/new line
    // or
    printf("hello");
    
}
Posted by: Guest on March-02-2020

Code answers related to "c++ string manipulation"

Browse Popular Code Answers by Language