#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <string>
#include <sstream>
using namespace std;
int main() {
string line;
while (getline(cin, line)) {
istringstream linestream(line);
int sum=0;
int x;
while (linestream >> x) {
sum += x;
}
cout<<sum<<endl;
}
}
分类: cplusplus
stl::list使用
auto it = hand.begin();
while (true) {
// 假设序列x,y。it指向x
// 这个y可能是list的end
// 备份 值
int bak_val = *it;
// 移除当前it所指,执行完后it指向y。执行完后序列变成y
hand.erase(it++);
// 之前备份的值 被插到y之前,执行完后序列变成了x,y。it指向y
hand.insert(it, bak_val);
// 若y是end,则该退出了
bool bre = false;
if (it == hand.end()) {
bre = true;
}
if (bre) {
break;
}
}
qt5 qpushbutton set img
->setStyleSheet("border-image:url(static/img/1.png);");
qt5 parent
- 可用用unique_ptr而不是qt的QScopedPointer,后者一般是因为历史遗留而使用
- widget.setLayout和layout.addWidget会让 参数中的 变成当前这个的child.
- 具有parent、child关系的组件中,父组件会自动销毁子组件。
不寄希望与c++帮我默认初始化啥
unordred_map<int,bool>[key]未设值前,获取到可能是true。
坑爹啊!!!
c long 使用
sscanf(k_mem, "%ld", &l_pid);
printk(KERN_INFO "k_mem=%s,read l_pid=%ld\n", k_mem, l_pid);
cmakelists 添加include文件夹
include文件夹中可能有很多其他文件夹。
target_include_directories(mytarget PRIVATE linux-master/include) mytarget是个通过add_executable弄的target
gcc xxx.c -lrt
这个-lrt必须放在最右边
-lrt表示使用library: librt
在CMakeLists.txt中指定lrt:
target_link_libraries(helloapp rt)
NAME
librt, libposix4 - POSIX.1b Realtime Extensions library
SYNOPSIS
cc [ flag... ] file... -lrt [ library... ]
DESCRIPTION
Functions in this library provide most of the interfaces
specified by the POSIX.1b Realtime Extension. See stan-
dards(5). Specifically, this includes the interfaces defined
under the Asynchronous I/O, Message Passing, Process
Scheduling, Realtime Signals Extension, Semaphores, Shared
Memory Objects, Synchronized I/O, and Timers options. The
interfaces defined under the Memory Mapped Files, Process
Memory Locking, and Range Memory Locking options are pro-
vided in libc(3LIB)
See the man pages for the individual interfaces in section
3RT for information on required headers.
The name libposix4 is maintained for backward compatibility
and should be avoided. librt is the preferred name for this
library.
当在linux下使用一些库,如<sys/shm.h>时,需要指定这个选项
clion cmake工程使用 gtest
- github上下载Google Test。并放到工程文件夹下。
工程目录结构如下:
☺ tree -L 1 master ✗
.
├── CMakeLists.txt
├── CMakeLists.txt.user
├── cmake-build-debug
├── googletest
├── main.cpp
└── src
googletest是之前从github上下载下来Google Test的仓库,并重命名后的。
src中的test目录是测试目录。
src下放【测试目录】和 自己的工程源码们:
☺ tree src master ✗
src
├── include
│ └── Config.h
├── test
│ └── utility
│ └── CellGameCoreTest.cpp
├── ui
│ ├── widget
│ │ └── game
│ │ ├── GameWidget.cpp
│ │ └── GameWidget.h
│ └── window
│ └── mainwindow
│ ├── MainWindow.cpp
│ ├── MainWindow.h
│ └── mainwindow.ui
└── utility
├── CellGameCore.cpp
├── CellGameCore.h
└── Rand_int.h
2. 项目的CmakeList.txt中需要引入GoogleTest。如下,引入了gtest和gmock
add_subdirectory(googletest)
include_directories(googletest/googletest/include)
include_directories(googletest/googlemock/include)
target_link_libraries(CellGame gtest gtest_main)
target_link_libraries(CellGame gmock gmock_main)
3. 接着开始写测试文件。可以看到test中采取了与工程类似的目录架构,这种架构风格还不错。
☺ tree src/test -L 3 master ✗
src/test
└── utility
└── CellGameCoreTest.cpp
TEST宏是gtest中的,第一个参数是Test Suit Name, 第二个参数是 Test Name。这两个Name之前有层级关系。在TEST中可以使用ASSERT_EQ等宏。
//
// Created by perci on 2020/5/21.
//
#include <src/utility/CellGameCore.h>
#include <vector>
#include "gtest/gtest.h"
TEST(CellGameCoreTest, SampleTest) {
CellGameCore core;
std::vector<std::vector<int>> vs;
vs.push_back(std::vector<int> {1,1,1});
vs.push_back(std::vector<int> {0,0,0});
vs.push_back(std::vector<int> {0,0,0});
std::vector<std::vector<int>> vs2 = core.process(vs);
ASSERT_EQ(vs2[0][0], 0);
ASSERT_EQ(vs2[0][1], 1);
ASSERT_EQ(vs2[0][2], 0);
ASSERT_EQ(vs2[1][1], 1);
return;
}
TEST(CellGameCoreTest, SampleTest2) {
CellGameCore core;
std::vector<std::vector<int>> vs;
vs.push_back(std::vector<int> {1,0,0});
vs.push_back(std::vector<int> {0,1,0});
vs.push_back(std::vector<int> {0,0,1});
std::vector<std::vector<int>> vs2 = core.process(vs);
ASSERT_EQ(vs2[0][0], 0);
ASSERT_EQ(vs2[0][1], 0);
ASSERT_EQ(vs2[0][2], 0);
ASSERT_EQ(vs2[1][1], 1);
}
4. 需要在CmakeList.txt中将测试文件添加到工程中。这里add_executable中新增了一个mytest的。
add_executable(mytest src/test/utility/CellGameCoreTest.cpp src/utility/CellGameCore.cpp)
target_link_libraries(mytest gtest gtest_main)
同时因为CellGameCoreTest.cpp中使用CellGameCore这个类,就引入了CellGameCore.cpp。(CellGameCore.cpp中引入了CellGameCore.h, 这样就相当于把这两个文件都引入了。光引入.h是不行的。)
5. 接着reload CmakeList.txt后,就会发现项目的Configuration
中有了mytest,接着就可以跑起测试了
截屏
java: 可用java.awt.Robot类,这个类可以截屏,可以模拟键盘输入、移动鼠标。
c++: Qt5的QScreen类,可截整个屏幕(但在ios下会因为安全、沙箱之类的原因不可截应用外的屏幕)
// c++ qt5, 截取整个屏幕作为 当前窗口 的背景图
QScreen *screen = QGuiApplication::primaryScreen();
if (screen) {
QPixmap bkgnd = screen->grabWindow(0);
bkgnd = bkgnd.scaled(this->size(), Qt::IgnoreAspectRatio);
QPalette palette;
palette.setBrush(QPalette::Background, bkgnd);
this->setPalette(palette);
}
// qt5官方的截屏软件例子:https://doc.qt.io/qt-5/qtwidgets-desktop-screenshot-example.html