We will make use of the C++ standard output stream, std::cout, to print messages from a running program to a terminal window. This will typically be done to display incoming MIDI message information.
#include <iostream> std::cout << "Hello World!" << std:endl; int myint = 55; std::cout << "My integer has the value of " << myint << std::endl; |
#include <vector> #include <iostream> int main() { std::vector<unsigned char> bytes; // zero-length vector of chars std::vector<int> ints1( 5 ); // 5 ints initialized to default value std::vector<float> floats1( 5, 2.0 ); // 5 floats initialized to 2.0 std::vector<int> ints2( ints1 ); // copy of "ints1" vector bytes.push_back( 144 ); // create a list of 3 byte values bytes.push_back( 64 ); bytes.push_back( 24 ); bytes[0] = 128; // modify the first value in the vector for ( unsigned int i=0; i<bytes.size(); i++ ) std::cout << "bytes[" << i << "] = " << (int) bytes[i] << std::endl; bytes.clear(); // remove all the elements in the vector std::cout << "bytes now holds " << bytes.size() << " elements." << std::endl; bytes.resize( 2 ); // resize the vector to the specified number of elements std::cout << "bytes now holds " << bytes.size() << " elements." << std::endl; bytes[3] = 79; // ERROR: attempt to write a value to the 4th element, which doesn't exist!!! return 0; } |
![]() | ©2003-2020 McGill University. All Rights Reserved. Maintained by Gary P. Scavone. |