Keyboard Input

Getting input from the keyboard via the command line #include <iostream> #include <string> #include <sstream> using namespace std; string entered_string; float my_float=0; int my_int=0; //Get input cout << "Enter something: "; getline(cin, entered_string); //Convert and display it stringstream(entered_string) >> my_float; //Will be 0 if invalid stringstream(entered_string) >> my_int; //Will be 0 if invalid if (entered_string.compare("4") […]

Read More

std::cout

Include variables and text like this: #include <iostream> std::cout << remote_client_address << " bytes received: " << bytes_received << std::endl; or #include <iostream> using namespace std; cout << remote_client_address << " bytes received: " << bytes_received << endl;  

Read More

Using console commands in code

The command line in Linux is so incredibly powerful with so many functions available to you via the OS and optional applications you can install.  It is often the easiest solution in C++ programs to just use the command line to achieve something you need doing rather than finding a harder way to do it in code and the following […]

Read More

printf

#include <stdio.h> Remember to include a terminating "\n" in your printf – stdout doesn't flush until it encounters one by default!!!! If printf still doesn't occur consider using std::cout instead printf("Hello world!\n"); printf("%i bytes read : %s\n", rx_length, rx_buffer); printf format codes d or i – int, decimal (base ten) number x or X – int, hexadecimal number ld – […]

Read More