#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
vector<wstring> words = { L"1", L"Goose", L"14", L"gas", L"/" , L"file10", L"file11" };
sort(words.begin(), words.end());
for(auto s : words)
{
wcout << s << " ";
}
wcout << endl;
wcin.get();
}
OUT: / 1 14 Goose file10 file11 gas
bool find(node* n, int value)
{
node* ptr = n;
while(ptr != nullptr)
{
if(ptr->value == value) return true;
ptr = ptr->next;
}
return false;
}
node* find(node* n, int value)
{
node* ptr = n;
while(ptr != nullptr)
{
if(ptr->value == value) return ptr;
ptr = ptr->next;
}
return ptr;
}
node* result = find(...);
if(result)
{
//...
}
What are the supported operating systems?
C:\Users\Angi\Desktop\DemoGame\x64\Debug\DemoGame.exe
var sqlite = require('sqlite-sync');
sqlite.connect(':memory:');
sqlite.run("CREATE TABLE TableName(Id INTEGER PRIMARY KEY, Key INTEGER NOT NULL)");
sqlite.run("INSERT INTO TableName VALUES(1, 892)");
var result = sqlite.run("SELECT Key FROM TableName WHERE Id = 1");
console.log(result[0].Key);
OUT: 892
#include <stdio.h>
#include <stdlib.h>
void swap(int* a, int* b)
{
int c = *a;
*a = *b;
*b = c;
}
void reverse(int* first, int* last)
{
while((first != last) && (first != --last))
{
swap(first++, last);
}
}
int* reverse_copy(int* first, int size)
{
int* result = (int*)malloc(size * sizeof(int));
for(int i = 0; i < size; ++i)
{
result[i] = first[size - i - 1];
}
return result;
}
int main()
{
int a[] = {0,1,2,3,4,5,6,7,8,9};
reverse(a, &a[10]);
for(int i = 0; i < 10; ++i)
{
printf("%d ", a[i]);
}
printf("\n");
int* b = reverse_copy(a, 10);
for(int i = 0; i < 10; ++i)
{
printf("%d ", b[i]);
}
free(b);
}
OUT:
9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "memdb");
db.setDatabaseName(":memory:");
if (!db.open())
{
qDebug() << db.lastError().text();
// std::exit(1);
}
QSqlQuery q("", db);
q.exec("create table Universities (id integer primary key, Location varchar, Population integer)");
q.exec("insert into Universities values (0, 'MSK', 12000000)");
q.exec("insert into Universities values (1, 'NSK', 1600000)");
q.exec("insert into Universities values (2, 'SPB', 6000000)");
q.exec("insert into Universities values (3, 'PRM', 1000000)");
int sz = ui->tableWidget->rowCount();
QString queryString = "SELECT * FROM Universities WHERE Location IN (";
for(int i = 0; i < sz; ++i)
{
queryString += "?,";
}
queryString.back() = ')';
QSqlQuery query(queryString, db);
for(int i = 0; i < sz; ++i)
{
query.bindValue(i, ui->tableWidget->item(i, 0)->text());
}
if (!query.exec())
{
qDebug() << query.lastError().text();
// std::exit(1);
}
while(query.next())
{
qDebug() << query.value(0).toInt() << " "
<< query.value(1).toString() << " "
<< query.value(2).toInt() << "\n";
}
QSqlQuery query;
query.prepare("SELECT * FROM Universities WHERE Location IN (?)");
int sz = ui->tableWidget->rowCount();
QVariantList values;
for(int i = 0; i < sz; ++i)
{
values << ui->tableWidget->item(i, 0)->text();
}
query.addBindValue(values);
if (!query.execBatch())
{
qDebug() << query.lastError();
}
необходимо по двойному клику на запись удалять её из tableWidget
int i = ui->tableWidget->selectionModel()->currentIndex().row();
ui->tableWidget->removeRow(i);
CLR не позволит и MessageBox привычным способом вызвать.
#include<Windows.h>
using namespace System;
int main(array<System::String ^> ^args)
{
#pragma comment(lib, "User32.lib")
MessageBox(NULL, L"Hello World!", L"Hello World Box", 0);
return 0;
}
p.s. название библиотеки поменялось
g++ main.cpp -o main.exe -lglfw3 //Компиляция происходит без проблем, а линковка дает ошибки
#include "glfw3.h"
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
undefined reference to `_imp__glClear@4'
то opengl32.a надо закинуть в project\libsusing an implementation-dependent algorithm or strategy
If you’re like me (with a front-end background and no CS degree) you look at this and think “Ok, variable assignment, variable assignment, function… simple enough…” but then you come to s1 ^= s1 << 23; and say “what the shit?”
filein.txt
Petya,K221,1,2,3;Vasya,K222,4,5,6;Senya,K223,7,8,0;Goga,K224,1,2,3;
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
using namespace std;
template<typename X = int>
struct Data
{
X one;
X two;
X three;
Data(X x1 = 0, X x2 = 0, X x3 = 0) : one{x1}, two{x2}, three{x3}
{}
};
template<typename X = int>
struct DataRecord
{
pair<string, string> text;
Data<X> data;
DataRecord(string _s1 = {}, string _s2 = {},
X _x1 = 0, X _x2 = 0, X _x3 = 0)
: text{_s1, _s2}, data{_x1, _x2, _x3}
{}
};
template<typename X = int>
istream& operator>>(istream& is, DataRecord<X>& record)
{
char c;
getline(is, record.text.first, ',');
getline(is, record.text.second, ',');
is >> record.data.one;
is >> c;
if(c == ',')
{
is >> record.data.two;
is >> c;
if(c == ',')
{
is >> record.data.three;
}
}
is >> c;
if(c != ';')
{
is.clear(ios_base::failbit);
}
return is;
}
struct DataSet
{
vector<DataRecord<>> records;
DataSet() : records{}{}
void load(string filename) noexcept;
Data<> sumsByColumns() noexcept;
};
void DataSet::load(string filename) noexcept
{
ifstream in(filename);
if(!in)
{
//...
return;
}
copy(istream_iterator<DataRecord<>>{in}, {}, back_inserter(records));
}
Data<> DataSet::sumsByColumns() noexcept
{
Data<> result;
for(const auto& rec : records)
{
result.one += rec.data.one;
result.two += rec.data.two;
result.three += rec.data.three;
}
return result;
}
int main()
{
DataSet ds;
ds.load("C:\\infile.txt");
Data<> result{ds.sumsByColumns()};
for(const auto& rec : ds.records)
{
cout << rec.text.first << '\t'
<< rec.text.second << '\t'
<< rec.data.one << '\t'
<< rec.data.two << '\t'
<< rec.data.three << '\n';// Если формат записей в файле
// построчный '\n' нужно убрать.
}
cout << "\nTotal:\t\t"
<< result.one << '\t'
<< result.two << '\t'
<< result.three << endl;
}
OUT
Petya K221 1 2 3
Vasya K222 4 5 6
Senya K223 7 8 0
Goga K224 1 2 3
Total: 13 17 12