Arturito.net

Come to The Dark Side, We Have Cookies!

Archive for the ‘C++’ Category

Visual Studio C# Regular Expressions Examples

leave a comment »

Numeric values:


public bool isNumeric(string str) {
Regex pattern = new Regex("[^0-9]");
return !pattern.IsMatch(str);
}

Alfa values:


private bool IsAlpha(string str) {
Regex pattern = new Regex("[^a-zA-Z]");
return !pattern.IsMatch(str);
}

Alfa numeric values:

private bool isAlfaNumeric(string str) {
Regex pattern = new Regex("[^a-zA-Z0-9]");
return !pattern.IsMatch(str);
}

Written by arturito

March 26, 2010 at 4:53 pm

Posted in C++

C++ Press any key to continue

leave a comment »

When I write some console application in Bloodshed Dev C++ or Visual Studio, I hate bringing up comand line and typing in the whole path to the program I’ve just written. I found two short ways of having “Press any key to continue…” before the console window disappears. One of them is a good one and the other is bad.

1. Good one

int main()

{

// do something

cout<<"Press Enter to continue...";
cin.get();
}

Well, this one really is “Press Enter to continue…”, which shouldn’t be a problem :-)

2. Bad one

int main()
{

// do something

system.("PAUSE");
}

This one is very bad! If you want to know why, read this article:

http://www.gidnetwork.com/b-61.html

Written by arturito

April 21, 2009 at 1:19 pm

Posted in C++

C++ Delay Function

leave a comment »

#include <ctime>

void delay(int n)
{
clock_t start_time, cur_time; start_time = clock();    while((clock() - start_time) < n * CLOCKS_PER_SEC)
{}
}

int main()
{
// do something
delay(5);
// delays 5 seconds
}

Written by arturito

March 24, 2009 at 9:38 pm

Posted in C++

C++ Integer to String conversion

leave a comment »

I wrote this little function which converts integer type variable to string. Always very handy!


#include <sstream>

string toString(int n)
{
string str;
stringstream out;
out<
return str = out.str();
}

box_logo

Written by arturito

February 24, 2009 at 7:32 pm

Posted in C++

Follow

Get every new post delivered to your Inbox.