avatar

Andres Jaimes

How to read a file name argument from the command line in C++

Reading a file name parameter from the command line is a common task. In this post I read a file name and validate it exists. For paths and file names that include spaces, you have to pass them between quotes, otherwise they will be interpreted by the operating system as two different parameters. #include <string> #include <iostream> #include <fstream> int main(int argc, char* argv[]) { for (int i = 1; i < argc; i++) { std::string s(argv[i]); if (s.

How to check command line arguments in any order

Here is an easy solution to passing parameters to a C++ application from the command line that does not require any external libraries. Since parameters are read inside a loop, the order in which they are passed is not important. #include <string> #include <iostream> int main(int argc, char* argv[]) { for (int i = 1; i < argc; i++) { std::string s(argv[i]); if (s == "-a") { std::cout << "You passed parameter -a" << std::endl; } else if (s == "-b") { std::cout << "You passed parameter -b" << std::endl; } else { std::cout << "Unknown: " << s << std::endl; } } return 0; }

Compiling and Debugging Oracle's Pro*C files in OS-X / Xcode

Part of my work as a Web/UNIX developer includes maintenance and development of tools using Oracle’s Pro*C. In text interfaces, VIM is a pretty decent tool for creating source code and their companion make files. If you created the right make file, compiling is also a breeze. However things get kind of tricky when you have to debug. Oh my! This can be a difficult task. Many may say that there’s nothing like gdb, but come on guys, even you can’t deny the beauty of a visual debugger.

How many bytes does an "int" have in c++?

Well, that depends on several things, like your current processor and compiler. The best way to know it, is by using the sizeof operator. Copy the following code, compile it and run it: #include <iostream> using namespace std; int main() { cout << "char: " << sizeof(char) << endl; cout << "int: " << sizeof(int) << endl; cout << "long: " << sizeof(long) << endl; return 0; } Happy coding…

A simple Makefile

Learning how to create a Makefile is one of those tasks every C/C++ programmer has to do. Since there are many good make tutorials on the web, I’m only going to share a simplistic makefile that you can use for your projects. CFLAGS=-c -Wall -Iinclude LDFLAGS=-lPocoFoundation -lPocoData SOURCES=a.cpp b.cpp main.cpp OBJECTS=$(SOURCES:.cpp=.o) VPATH=src all: pre $(OBJECTS) g++ $(OBJECTS) -o build/main $(LDFLAGS) .cpp.o: g++ $(CFLAGS) $< -o $@ pre: mkdir -p build clean: rm -Rf build rm -f *.

How to setup a FastCGI development environment in CentOS 6

Install the development environment Install the C/C++ development tools to your server: yum install gcc gcc-c++ autoconf automake Now, before installing fcgi we need to add the epel repository: rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm Once it is installed we can proceed to get the fcgi packages: yum install fcgi-devel spawn-fcgi Let’s see if we can compile a simple file. Create a file named example.c and copy and paste the following code in it:

A simple C++/Wt (Witty) skeleton for starting an application

The objective of this lesson is to show you how to make a simple web page navigation using Wt. Before starting you have to remember that Wt can be used to create 1 URL applications. That means you can have a full application that runs using just one URL. However it is also useful to give your users different URL’s to take advantage of some browser features like bookmarks or the back and forward buttons.

How to use a WComboBox with C++/Wt (Witty)

In this entry I’m going to create a simple form that shows how to add items to WComboBox in two different ways. The first one is useful for static combo items while the second one might be used to populate a combo from a database. The code is based on our previous Hello World application. There are few lines that changed.  Using Static Combo Items Adding items to a WComboBox is just a matter of calling the addItem method.

Creating a simple form using C++/Wt (Witty)

In this entry I’m going to create a simple form. This form will show you how to use controls and events in a very simple way. A couple things you have to notice before we start: I’m going to inherit from WContainerWidget. As you now know, I could have inherited from WApplication too. Most controls like, WLabel, WLineEdit and WPushButton include a “parent” parameter in their constructors. But you can also create them and add them later to any WContainerWidget.

Two ways to create a Hello World application with Wt (Witty)

Let’s start by talking a little bit about some elements and methods you will find in the code. Inheriting from WApplication or WContainerWidget are the most common ways to start an application using Wt. A WApplication instance will be in charge of creating your html, head and body tags. A WContainerWidget is usually a div tag (it can also be turned into a ul or ol by using its setList method).