Sunday, July 30, 2006

C++ stuff

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home