Using Strings-Values

Using the stringstream class Add variable to string This is a nice easy way to add values to strings and just create strings easily. Get variable from string Converting double to string with a fixed number of decimal places Modifiers “hex” Make values hexadecimal.  Persistent.  Reset back to normal by using “dec”. uppercase Make values beign […]

Read More

Using Strings-Searching Strings

Does String Contain if (s1.find(s2) != std::string::npos) cout << "String found!" << endl; Do Strings Match if (my_string1.compare(my_string2) == 0) //0=strings are the same { //Strings match } Does String Start With if (CommandResult.find("abc") == 0) Find first occurrence string s1 = "hello world"; if (s1.find(' ') != string::npos) { cout << "Space found " […]

Read More

.Using Strings-Basics

Creating and using strings If you get errors? You may be defining the strings somewhere not allowed so instead try defining the strings separately at the top of the function, e.g.: Does string equal switch (MyString) ? No, you can’t use switch() on a string in c++ Passing String to a function that expects char […]

Read More

.Char based Strings General

Header Files #include <string.h> Creating Strings static const char *my_define = "/etc/sysconfig/network"; const char *mytext = "Hello World"; String Length int mytext_length = strlen(mytext); Does String Contain if (strncmp(*++argv, "O_RDONLY", 8) == 0) open_mode |= O_RDONLY; Copy String The preferred way strncpy (string_destination, string_source, max_length); //Note no null will be included if the string is […]

Read More

Getting the project files

Get the project files from the RPi? To find out where NetBeans copies the files to on the RPi look in the 'Output' window for "Entering directory", e.g.: make[1]: Entering directory '/root/.netbeans/remote/192.168.1.183/dell-m4600-win7-Windows-x86_64/C/_PROJECTS/SomeFolderName/Apps/MyApp/MyAppName' Note that if you look for this location using the GUI file manager you will need to select the menu option View > Show hidden […]

Read More

rapidjson

Nice and simple json reader and writer library.  No dependence on other libraries, just add rapidjson to you project and go. Download from here. Use the tutorial or look in \examples\ for how to use.

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

Adding Libraries

Adding A Library To A NetBeans Project For example the bcm2835 library for the IO pins. Include the library header file #include <bcm2835.h> When you compile you the compiler also needs to include the library so the libraries object file is added to the final compilation. Right click the project > Properties > Build > Linker > In […]

Read More

.Creating A New Project

Compatability We’re still using this in 2023 with NetBeans IDE 11.0 with no problems. See here for the netbeans 11 setup. Enabling Running Remote Projects in NetBeans As Root User By default the root account is disabled in Raspbian, but for an application to access the IO pins it needs root user privileges.  There are ways to […]

Read More