Beispiel #1
0
int main() {
	// 🐨 has unicode codepoint U+1F428 (http://emojipedia.org/koala/)
	// according to UTF-8, we have to store 1 11110100 00101000:
	// [1111]0000 [10]011111 [10]010000 [10]101000
	// 4 bytes for koala!
	String sample1("🐨 коала emoji"); // 13 user-perceived characters (http://utf8everywhere.org/)
	String sample2(sample1); // copy constructor
	std::string sample3(sample1.str);
	std::cout << sample1.size << " " << sample3.length() << '\n'; // 21 21
	size_t len = 0;
	char *s = sample1.str;
	while (*s) len += (*s++ & 0xc0) != 0x80; // UTF-8 — count all bytes that do not match 10xxxxxx
	std::cout << len << '\n'; // 13
	return 0;
}
Beispiel #2
0
int main (int argc, char ** argv)
{
    FILE * mpgfile;

    if (argc > 1) {
	mpgfile = fopen (argv[1], "rb");
	if (!mpgfile) {
	    fprintf (stderr, "Could not open file \"%s\".\n", argv[1]);
	    exit (1);
	}
    } else
	mpgfile = stdin;

    sample3 (mpgfile);

    return 0;
}
Beispiel #3
0
int main(int argc, char** argv)
{
	Poco::MongoDB::Connection connection("localhost", 27017);

	sample1(connection);
	sample2(connection);
	sample3(connection);
	sample4(connection);
	sample5(connection);
	sample6(connection);
	sample7(connection);
	sample8(connection);
	sample9(connection);
	sample10(connection);
	sample11(connection);
	sample12(connection);
	sample13(connection);

	return 0;
}
Beispiel #4
0
int
main(int argc, char *argv[])
{
	std::cout << "\ncpp_samples: main: Init" << std::endl;

	A a = { NULL, 8 };

	std::cout << "\ncpp_samples: main: a.x: " << a.x << std::endl;
	std::cout << "cpp_samples: main: a.y: " << a.y << std::endl;

	SOA soa = { { 2, 4, 8, 1, 3 }, {{ 1, 4, 7, 9, 0, 4 }, { 8, 2, 9, 1, 6, 3 }} };

	std::cout << "\ncpp_samples: main: soa.a[0]: " << soa.a[0] << std::endl;
	std::cout << "cpp_samples: main: soa.a[1]: " << soa.a[1] << std::endl;
	std::cout << "cpp_samples: main: soa.a[2]: " << soa.a[2] << std::endl;
	std::cout << "cpp_samples: main: soa.a[3]: " << soa.a[3] << std::endl;
	std::cout << "cpp_samples: main: soa.a[4]: " << soa.a[4] << std::endl;
	std::cout << "cpp_samples: main: soa.b[0][2]: " << soa.b[0][2] << std::endl;
	std::cout << "cpp_samples: main: soa.b[1][1]: " << soa.b[1][1] << std::endl;
	std::cout << "cpp_samples: main: soa.b[0][3]: " << soa.b[0][3] << std::endl;
	std::cout << "cpp_samples: main: soa.b[1][5]: " << soa.b[1][5] << std::endl;
	std::cout << "cpp_samples: main: soa.b[0][3]: " << soa.b[0][3] << std::endl;

	C c = { 78, 126 };

	std::cout << "\ncpp_samples: main: c.x: " << c.x << std::endl;
	std::cout << "cpp_samples: main: c.y: " << c.y << std::endl;

	Box box1;
	Box box2;

	box1.setLength(43);
	box1.setWidth(83);
	box1.setHeight(91);

	box2.setLength(78);
	box2.setWidth(92);
	box2.setHeight(19);

	uint64_t volume = 0;

	volume = box1.getVolume();
	std::cout << "Volume: box1: " << volume << std::endl;

	volume = box2.getVolume();
	std::cout << "Volume: box2: " << volume << std::endl;


	RGBColour rgb1;
	RGBColour rgb2;

	rgb1.red = 83;
	rgb1.green = 10;
	rgb1.blue = 39;

	rgb2.red = 43;
	rgb2.green = 13;
	rgb2.blue = 71;

	std::cout << "Colour: box1: rgb1: Red: " << (short)rgb1.red << " Green: " << (short)rgb1.green << " Blue: " << (short)rgb1.blue << std::endl;

	std::cout << "Colour: box2: rgb2: Red: " << (short)rgb2.red << " Green: " << (short)rgb2.green << " Blue: " << (short)rgb2.blue << std::endl;

	sample2();

	sample3();

	sample4();

	return 0;
}