Keanehan dan keunikan yang ada di dunia

03 November 2009

Introduction to strings

Variables that can store non-numerical values that are longer than one single character are known as strings.

The C++ language library provides support for strings through the standard string class. This is not a fundamental type, but it behaves in a similar way as fundamental types do in its most basic usage.

A first difference with fundamental data types is that in order to declare and use objects (variables) of this type we need to include an additional header file in our source code: and have access to the std namespace (which we already had in all our previous programs thanks to the using namespace statement).

1
2
3
4
5
6
7
8
9
10
11
// my first string
#include 
#include 
using namespace std;

int main ()
{
  string mystring = "This is a string";
  cout << mystring;
  return 0;
}
This is a string


As you may see in the previous example, strings can be initialized with any valid string literal just like numerical type variables can be initialized to any valid numerical literal. Both initialization formats are valid with strings:

1
2
string mystring = "This is a string";
string mystring ("This is a string");


Strings can also perform all the other basic operations that fundamental data types can, like being declared without an initial value and being assigned values during execution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// my first string
#include 
#include 
using namespace std;

int main ()
{
  string mystring;
  mystring = "This is the initial string content";
  cout << mystring << endl;
  mystring = "This is a different string content";
  cout << mystring << endl;
  return 0;
}
This is the initial string content
This is a different string content

Tags

10 fakta unik 12-12-2012 17 + 5 fakta unik 6 fakta unik 7 fakta unik 8 fakta unik 9 fakta unik adegan ranjang ajaib akhir zaman alien alien di bumi aljabar linear all about cinta aneh anime antivirus artis barat artis china artis dalam negri artis dunia artis hot artis india artis jepang artis lucu artis pendatang baru award babi aneh banci banten Belajar PHP bencong berita berita dewasa berita indonesia berita terbaru berita unik bertta bintang film porno bintang porno jepang blog tutorial bocah unik boneka terseram buaya panjang 12 m C++ cantik cari uang mudah cewek cantik cewek facebook cewek nekat cewek panggilan cewek rusia Cheerleader Contact curhat dapat uang 10 - 15 juta perbulan. desa terapung desain unik dewasa djarum black competition f facebook fb cewek cantik fenomena alam film film indonesia finalis miss indonesia 2013 foto artis foto HOT foto lucu foto panas foto unik ga gadis gadis cantik gambar artis lokal gambar artis luar gambar berbahaya gambar HOT gambar lucu gambar sexy gambar unik game game indonesia game seru hack handphone terbaru hewan aneh hewan berbahaya hewan unik honey moon Hujan yang aneh indonesia unik IT jadul jav java jepang jepang unik jual septic tank kamus bencong kamus waria kanibal karya unik keajaiban Tuhan keanehan dunia keberadaan alien kelakuan pria kesehatan keunikan alam keunikan hewan keunikan manusia kiamat kiamat 2012 koleksi foto tasya djerli komputer kota terunik kota unik kreatif kucing berdoa kuliner lab Algoritma laptop jadul lirik lagu lorong waktu luar biasa luna maya maho makanan makanan aneh makanan unik manusia hebat manusia liliput manusia raksasa manusia unik maria ozawa materi kuliah mengapa pesawat sukhoi jatuh? pramugari pesawat sukhoi mengerikan Mesin waktu mey meydiana sari miss banten miss indonesia miss indonesia 2013 miss indonesia meydi misteri mistis motivasi nekat payudara penampakan alien Penemuan pengetahuan umum penghargaan nobel penghasilan penyakit aneh penyebab pesawat sukhoi jatuh perwakilan banten pesawat sukhoi pesawat sukhoi jatuh pohon aneh pria maho ramalan dunia ramalan kiamat renungan reseller rin sakuragi rohani rumah unik sejarah sejarah windows selebritis septic tank septic tank biological septic tank fiberglas septic tank modern septic tank murah septictank bio seputar hantu seram sora aoi spiteng fiber spiteng fibreglass tahukah anda tangki septic tank tato 3D teknologi terbaru tikus jadi ayam tips and trik blog tips kesehatan tips unik tumbuhan unik tutorial facebook unik unik-unik video porno waria windows 8 wisata kuliner

TaTTiTTuT Blog Copyright © 2011 | Template created by O Pregador | Powered by Blogger