How Do You Troubleshoot the C Program Error “error: expected ‘;’ before string constant”?

Problem scenario
You try to compile a program with “gcc nameofprog.cc”.  You get this output: “foobar.cc.:55:error: expected ‘;’ before string constant”

What do you do to compile your program?

Solution
Go to line 55 of foobar.cc.  If there is a printf command, be sure that the thing to be printed is surrounded by parentheses.  Here is an example of a line that will cause the problem:
   printf “This is a test”;

How Do You Troubleshoot the C Program Error “warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]”?

Problem scenario
You try to compile a program with “gcc nameofprog.cc”.  You get this output:

“warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]”

What do you do to compile your program?

Solution
The program may still compile and run.  Look for the a.out file to be created.  It may be a working C program.  Just run it like this:  ./a.out

To get rid of the error,

How Do You Install a C Compiler on Linux?

Problem scenario
You want to program in the C programming language on a Linux server.  How do you code in C and test your programs?

Solution
Overview

Install the C compiler.

Procedures
1.  To find your distribution of Linux run this command:  cat /etc/*-release | grep -i pretty

2.  Find the one option of the below three that applies to your Linux:

  • For a Red Hat distribution (e.g.,

How Do You Read in Keyboard Input from a User and Invoke a Unix Shell Command with a C++ Program?

Problem scenario
You want to see how C++ works.  You want to read in user input from the keyboard and have the C++ program run a bash command.  How do you do this?

Solution
Compile this code (e.g., as a file named “test.cpp” with “g++ test.cpp”) and run it (e.g., ./a.out):

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

How Do You Use the C++ Connector for Libpqxx?

Problem scenario
You want to integrate C++ programs with Postgresql on an Ubuntu instance of AWS.  You want to use pqxx (http://pqxx.org/development/libpqxx/) as it is an API connector for C++ to Postgres.  How do you use libqxx?

Solution
#1  Install Postgresql.  To install Postgresql, run this as root or with a “sudo ” in front of it: apt-get install postgresql

#2  To execute SQL commands,

How Do You Install pqxx on an AWS Instance of Ubuntu?

Problem scenario
You try to compile a C++ program (i.e., a .cpp file).  You get this message:  “fatal error:  pqxx/pqxx: No such file or directory.”  You want to install pqxx on your Ubuntu server in AWS.  What do you do?

Solution
#1  Log into the server.  Run this command as root or with a sudo in front it:

add-apt-repository ppa:jtv/ppa 
#Press enter in response to the prompt from the command above.

Using Ubuntu, How Do You Install a C++ Compiler and Run a Basic C++ Program?

Problem scenario
You want to install a C++ compiler in Ubuntu.  You want to write a basic C++ program and run it.  How do you do these things?

Solution
1. As root, install a C++ compiler with this command:

apt install g++

2. Create a basic program.  Here is an example.  Name this file hello.cpp and put this as the content:

#include <iostream>

How Do You Use C++ to Retrieve Data from a PostgreSQL Database on Ubuntu Linux?

Problem scenario:  You have C++ and Postgres installed on an Ubuntu Linux server.  How do you write C++ programs to retrieve data from Posgres databases?

Solution
Install the official C++ API for Postgresql.  These directions should work on any Debian distribution of Linux.

As root, do the following from the Linux command prompt:

apt-get -y install libpq-dev g++
cd /usr/bin/
curl http://pqxx.org/download/software/libpqxx/libpqxx-4.0.tar.gz >