#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
#include <iconv.h>
string iconv_recode(const string from, const string to, string text)
{
iconv_t cnv = iconv_open(to.c_str(), from.c_str());
if (cnv == (iconv_t) - 1) {
iconv_close(cnv);
return "";
}
char *outbuf;
if ((outbuf = (char *) malloc(text.length()*2 + 1)) == NULL) {
iconv_close(cnv);
return "";
}
char *ip = (char *) text.c_str(), *op = outbuf;
size_t icount = text.length(), ocount = text.length()*2;
if (iconv(cnv, &ip, &icount, &op, &ocount) != (size_t) - 1) {
outbuf[text.length()*2 - ocount] = '\0';
text = outbuf;
} else {
text = "";
}
free(outbuf);
iconv_close(cnv);
return text;
}
void compare_strings(const string &aString1, const string &aString2) {
cout << "String 1: " << aString1 << endl
<< "String 2: " << aString2 << endl;
if (aString1 == aString2) {
cout << "Identical strings!" << endl
<< "-----" << endl;
} else {
cout << "Different strings!" << endl
<< "-----" << endl;
}
}
int main()
{
ifstream file_1("word_1.txt"); // The "Proverka" Word in UTF-8
ifstream file_2("word_2.txt"); // The "Proverka" Word in CP1251
string word_1, word_2;
file_1 >> word_1;
file_2 >> word_2;
compare_strings(word_1, word_2);
word_2 = iconv_recode("CP1251", "UTF-8", word_2);
compare_strings(word_1, word_2);
return 0;
}
exl@exl-Lenovo-G560e:~/SandBox/text_enc > enca -L russian word_1.txt
Universal transformation format 8 bits; UTF-8
Doubly-encoded to UTF-8 from ISO-8859-5
exl@exl-Lenovo-G560e:~/SandBox/text_enc > enca -L russian word_2.txt
MS-Windows code page 1251
LF line terminators
exl@exl-Lenovo-G560e:~/SandBox/text_enc > cat word_1.txt
Проверка
exl@exl-Lenovo-G560e:~/SandBox/text_enc > cat word_2.txt
��������
exl@exl-Lenovo-G560e:~/SandBox/text_enc > ./text_coding
String 1: Проверка
String 2: ��������
Different strings!
-----
String 1: Проверка
String 2: Проверка
Identical strings!
-----
#include "qpaintwidget.h"
#include <QPainter>
#include <QDebug>
QPaintWidget::QPaintWidget(QWidget *parent)
: QWidget(parent)
{
offset = 0;
resize(800, 600);
paintTimer = new QTimer(this);
paintTimer->start(10);
connect(paintTimer, SIGNAL(timeout()), this, SLOT(updatePixmap()));
}
void QPaintWidget::paintEvent(QPaintEvent *)
{
QColor whitebrush = Qt::white;
QColor blackbrush = Qt::black;
QColor redbrush = Qt::darkRed;
QPainterPath path;
QPainter painter(this); // Создаём новый объект рисовальщика
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
painter.translate(1 + offset, 0);
painter.setBrush(whitebrush);
painter.drawRect(0, 0, width(), height());
QPoint triangle[3] = {
QPoint(180, 450),
QPoint(220, 450),
QPoint(200, 555),
};
painter.setBrush(blackbrush);
painter.drawEllipse(10, 15, 380, 380);
painter.setBrush(redbrush);
painter.drawEllipse(35, 8, 330, 330);
painter.setBrush(whitebrush);
painter.drawEllipse(50, -5, 300, 330);
painter.setBrush(blackbrush);
painter.drawPolygon(triangle, 3);
path.setFillRule(Qt::WindingFill);
path.addRect(180, 250, 40, 200);
path.addRect(150, 250, 100, 20);
painter.drawPath(path);
painter.setBrush(whitebrush);
painter.drawEllipse(120, 260, 60, 20);
painter.drawEllipse(220, 260, 60, 20);
}
void QPaintWidget::updatePixmap()
{
(offset >= 810) ? offset = 0 : offset+=5;
qDebug() << offset;
repaint();
}
QPaintWidget::~QPaintWidget()
{
}
#ifndef QPAINTWIDGET_H
#define QPAINTWIDGET_H
#include <QWidget>
#include <QTimer>
class QPaintWidget : public QWidget
{
Q_OBJECT
int offset;
QTimer *paintTimer;
protected:
void paintEvent(QPaintEvent *);
private slots:
void updatePixmap();
public:
QPaintWidget(QWidget *parent = 0);
~QPaintWidget();
};
#endif // QPAINTWIDGET_H
MY_HEADER_PATH := ../src/headers
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/$(SDL_IMAGE_PATH)/ \
$(LOCAL_PATH)/$(SDL_MIXER_PATH)/ \
$(LOCAL_PATH)/$(SDL_TTF_PATH)/ \
$(LOCAL_PATH)/$(MY_HEADER_PATH)/
LOCAL_CХХ_INCLUDES :=
или LOCAL_CPP_INCLUDES :=
exl@exl-Lenovo-G560e:~/SandBox > cat test.cpp
#include <iostream>
int main() {
int f = 15;
for(int i = --f; i > 0; --i)
std::cout << i << " ";
std::cout << std::endl;
return 0;
}
exl@exl-Lenovo-G560e:~/SandBox > g++ test.cpp
exl@exl-Lenovo-G560e:~/SandBox > ./a.out
14 13 12 11 10 9 8 7 6 5 4 3 2 1
exl@exl-Lenovo-G560e:~/SandBox > cat test.cpp
#include <iostream>
int main() {
int f = 15;
for(int i = f--; i > 0; --i)
std::cout << i << " ";
std::cout << std::endl;
return 0;
}
exl@exl-Lenovo-G560e:~/SandBox > g++ test.cpp
exl@exl-Lenovo-G560e:~/SandBox > ./a.out
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Depends: libflac-dev (>= 1.2.1)
Depends: libmad0-dev (>= 0.15.1b)
Depends: libmikmod2-dev (>= 3.1.11)
Depends: libogg-dev (>= 1.2.0)
Depends: libsdl-mixer1.2 (= 1.2.12-3)
Depends: libsdl1.2-dev (>= 1.2.14~)
Depends: libvorbis-dev (>= 1.2.0)
sudo apt-get install libflac-dev libmad0-dev libogg-dev libvorbis-dev libmikmod2-dev
./configure --enable-music-mod-mikmod --enable-music-mod-mikmod-shared --enable-music-mp3-mad-gpl --enable-music-ogg --enable-music-flac
make -j4
sudo make install
checking for libmikmod-config... /usr/bin/libmikmod-config
checking for libmikmod - version >= 3.1.10... yes
-- dynamic libmikmod -> libmikmod.so.2
...
checking vorbis/vorbisfile.h usability... yes
checking vorbis/vorbisfile.h presence... yes
checking for vorbis/vorbisfile.h... yes
checking for ov_open_callbacks in -lvorbisfile -lvorbis -logg -lm... yes
-- dynamic libvorbisfile -> libvorbisfile.so.3
...
checking for FLAC__stream_decoder_new in -lFLAC... yes
-- dynamic libFLAC -> libFLAC.so.8
...
checking for libmad headers... yes
#include <SDL.h>
#include <SDL_mixer.h>
#include <iostream>
int main(int argc, char *argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
std::cout << Mix_GetError() << std::endl;
Mix_Music *mus;
mus = Mix_LoadMUS("m.ogg");
std::cout << Mix_GetError() << std::endl;
Mix_PlayMusic(mus, 1);
SDL_Event event;
int done = 0;
while(!done && Mix_PlayingMusic()) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
}
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_ESCAPE) {
done = 1;
}
}
}
}
Mix_FreeMusic(mus);
Mix_Quit();
SDL_Quit();
}