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 " […]
All posts by
.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 […]
.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 […]
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 […]
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.
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;
Sockets – General
Good C/C++ Resources For Programming Sockets Beej's Guide to Network Programming << Great resource
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 […]
.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 […]
Networking
More Networking Things Our Raspbian specific networking stuff is here: https://raspberry-projects.com/pi/category/pi-operating-systems/raspbian/network-settings IP Address ip addr Is A Specific Interface Connected ip link show wlan0 WiFi List discovered networks sudo iwlist wlan0 scan Is network connected ifconfig wlan0 If the inet addr field has an address beside it, the RPi has connected to the network. Get connected […]
