Skip to content
View in the app

A better way to browse. Learn more.

GTAGames.nl - De Nederlandse Grand Theft Auto Community!

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C++ De Basis - Strings

(0 reviews)

logo_cpp_1.png

We behandelen deze keer de strings. Een string is simpelweg tekst.


[table=header]Nota:

Dit artikel is door @Megadreams aangeduid als "moet herschreven worden".[/table]

screen15.png

screen16.png

We gaan 2 includes includen namelijk "iostream" en "string" de include string is nodig voor de strings:

#include <iostream>
#include <string>

Dan weer de namespace:

using namespace std;

Nu gaan we de procedure "main" weer aanmaken:

int main()
{

}

Nu gaan we geen int gebruiken maar string en deze string noemt "woord":

string woord;

We gaan nu de gebruiker vertellen dat hij een woord/tekst moet invoeren, dit doen we met "cout":

cout << "Voer een woord/tekst in: ";

Nu gaan we het woord of de tekst ophalen via cin:

cin >> woord;

En nu gaan we het ingevoerde woord/tekst op het scherm schrijven:

cout << "Je voerde het volgende woord/tekst in: " << woord;

En nu gaan we onze welbekende loop weer gebruiken want als je cin.get() zou gebruiken zou hij net als bij het vorige programmatje meteen afsluiten want je drukt immers nog die toets "enter" in:

while(true){}

Nu sluiten we af met een return:

return 0;

Dit alles samen vormt:

#include <iostream>
#include <string>
using namespace std;

int main()
{
string woord;
cout << "Voer een woord/tekst in: ";
cin >> woord;
cout << "Je voerde het volgende woord/tekst in: " << woord;

while (true){}
return 0;
}

Volgende keer zullen we de verschillende soort loops behandelen en wat je er allemaal mee kan.

3 Comments

Recommended Comments

Big Boss Legendary Godfather

Big Boss

Ereleden

       int b = 1;
       while (b = 1)
       {

       }

Is dat niet gewoon hetzelfde als dit, of?

while(true) { }

Megadreams Kingpin

Megadreams

Leden

Klopt maar ik had dit ook al een tijdje geleden geschreven en wat het vergeten aan te passen. :bonk:

Basssss The Godfather

Basssss

Leden

Vond deze tutorial eigenlijk niet veel toevoegende waarde hebben tegenover de vorige tutorials. Het enige verschil is eigelijk het woordje 'string', wat in de vorige tutorial 'int' was. :(

Guest
Add a comment...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.