Thomas Sampson

C++ stuff

Leave a comment

So today I did a refresher on some basic C++ stuff. I thought i’d just note down a few things worth remembering.

Writing / Reading from console app

Here there are 2 prerequisites

#include <iostream>

this line includes the input output stream for the console and…

using namespace std;

this line is required to utilize the standard namespace, giving access to functions like cin and cout (console input and output)

Functions

One thing i’m finding hard to come to grips with is the fact that any functions you use must be declared beforehand, for example

int go(int inputargument);

then….

int go(int inputargument)
{
logic
}

Strings

To use strings in C++ you must

#include <string>

with optional extras for dealing with strings

#include <cstring>
#include <sstream>

sstream is is “String Stream” which allows you to convert integers to strings like so

int mynum=5;
string temp;
stringstream ss;
ss<<mynum;
temp=ss.str();

Definitions

also, any variable that willnot change throughout the whole app can be declared underneath any includes using

#define variablename value

example

#define maxnumber 100

Advertisements

Author: tomtech999

I have recently graduated with a 1st class degree in MComp Games Software Development at Sheffield Hallam University, focusing primarily on application development in C++, with experience in graphics programming, scripting languages, DVCS/VCS and web technology. In my spare time I enjoy Drumming, Reading and Snowboarding!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s