typedef struct {
char* name;
} MyStruct;
void serialize(ostream& os, const MyStruct& obj)
{
char* p = (char*) obj;
for (int n = 0; n != sizeof(MyStruct); ++n)
os << *p;
}
// Удаление первых n слов из строки
string dellwords(const string& st, int n)
{
string result;
string::const_iterator it = st.begin();
enum {
SkipWhitespace,
SkipWord,
CopyText
} state = SkipWhitespace;
while (it != st.end()) {
switch (state) {
case SkipWhitespace:
if (! isspace(*it)) {
if (n == 0) {
state = CopyText;
result += *it;
}
else
state = SkipWord;
}
break;
case SkipWord:
if (isspace(*it)) {
state = SkipWhitespace;
--n;
}
break;
case CopyText:
result += *it;
break;
}
++it;
}
return result;
}
int main()
{
setlocale(LC_ALL, "RUSSIAN");
string text;
cout << "Введите текст: ";
getline(cin, text);
// удаляю слова «Запись» и «исходного» из строки
cout << dellwords(text, 2) << endl;
return 0;
}
bool alreadyDisplayed [lastStringCount + 1];
for (int n = 0; n < lastStringCount; ++n)
alreadyDisplayed[n] = false;
int index;
do {
index = random(0, LastStringCount );
} while (alreadyDisplayed[index] == true);
alreadyDisplayed[index] = true;
typedef void (*MyFunc)();
char my_code[] = { 0xDE, 0xAD, 0xBE, 0xEF );
MyFunc f1 = (MyFunc) my_code;
f1();
const int viewport_width = 640;
const int viewport_width = 480;
class Triangle
{
public:
static Triangle* create(Triangle* instance = nullptr) {
if (instance == nullptr) {
instance = new Triangle;
if (instance == nullptr)
throw Exception("Can't create Triangle object");
}
// инициализация
instance->A = 0;
instance->B = 0;
instance->C = 0;
return instance;
}
};
...
Triangle* myTriangle = Triangle::create();
cin >> str1 >> str2;