我对c和Raspberry Pi相对较新,我正在尝试简单的程序.我想要的是当按下按钮时printfs一次并且不再打印,直到再次按下按钮,即使按下按钮(类似闩锁).我想可能会添加第二个while循环来解决这个问题,但有时它仍然没有检测到按下按钮.
#include <bcm2835.h>
#include <stdio.h>
#define PIN RPI_GPIO_P1_11
int main()
{
if(!bcm2835_init())
return 1;
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT);
while(1)
{
if(bcm2835_gpio_lev(PIN))
{
printf("The button has been pressed\n");
}
while(bcm2835_gpio_lev(PIN)){}
}
bcm2835_close();
return 0;
}
Run Code Online (Sandbox Code Playgroud) 作为前瞻性声明的重要使用者,我喜欢我的课程在破坏时完成.为了确保这一点,我将析构函数设为私有并成为朋友boost::checked_delete:
#include <boost/checked_delete.hpp>
struct MyClass
{
//MyClass's interface
private:
~MyClass() { /* something */ }
friend void boost::checked_delete<>(MyClass* x);
};
Run Code Online (Sandbox Code Playgroud)
在C++ 11中,std::default_delete还会检查销毁时的完整性.然而,我无法实现与上述相同的行为:
#include <memory>
struct MyClass
{
//MyClass's interface
private:
~MyClass() { /* something */ }
friend struct std::default_delete<MyClass>;
};
int main()
{
//const std::shared_ptr<MyClass> d {
// std::make_shared<MyClass>()
//}; //(1) Should compile?
const std::shared_ptr<MyClass> d(
new MyClass,std::default_delete<MyClass>()
); //(2) Does compile
}
Run Code Online (Sandbox Code Playgroud)
我想知道
std::make_shared是一件好事我正在使用GCC 4.8.0,我检查了-std = c ++ 11和-std = c …
我正在尝试使用mapbox.js创建一个经度和纬度选择器,我需要这个地图位于一个模式框中,当我点击"选择位置"按钮时会打开它.但是当这个模态打开时,地图不会完全呈现.
这是我的代码:
<div class="modal fade" id="chooseLocation" tabindex="-1" role="dialog" aria-labelledby="chooseLocation" aria-hidden="true">
<div class="Cadd-event-modal" style="width: 600px; margin: 0px auto; margin-top: 10%;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title Cfont-1">Choose location</h4>
</div>
<div class="modal-body" style="width: 500px; margin: 0px auto;">
<div id='map'></div>
<div class='map-overlay'>
<label for='latitude'>latitude</label><br />
<input type='text' size='5' id='latitude' /><br />
<label for='longitude'>longitude</label><br />
<input type='text' size='5' id='longitude' />
</div>
</div>
<div class="model-footer"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
脚本
var map = L.mapbox.map('map', 'examples.map-9ijuk24y')
.setView([0, 0], 2);
// get the form …Run Code Online (Sandbox Code Playgroud) 我继承了我需要为我的工作更新的代码库.我正在慢慢地学习他们正在尝试使用现有的闭包来完成什么,但是在尝试更新使用此功能的网站的一部分时我遇到了困难.我将给出代码试图完成的基本概述,看看是否有人可以提供帮助.
var TheObject = (function (){
var veryLargeDependantData = {
var1: {},
var2: {},
var3: [],
//Set these variables via functions
function1: function f1(data){...},
function2: function f2(data){...},
initialize: function initialize() { //set values for var1... var3}
};
return {initialize: veryLargeDependentData.initialize};
})().initialize();
Run Code Online (Sandbox Code Playgroud)
由于我显然无法在网站上显示生产代码,因此必须这样做.但基本上,VeryLargeDependentData变量是函数的入口.当页面加载时,它调用初始化函数,一切都很愉快.但是现在我需要将它添加到onclick事件和旧页面,而firebug控制台说该变量是未定义的.在其他页面中,我可以毫无问题地使用它.
我的问题是,正在发生什么导致闭包不能成为像这样的可调用命名空间的一部分.我有点像javascript nOOb,所以如果问题听起来有误,我会道歉.
onclick='TheObject.initialize();'
Run Code Online (Sandbox Code Playgroud) 我正在使用 gin gonic 构建一个 Web 应用程序。我使用https://github.com/gin-gonic/contrib/tree/master/sessions来处理会话。例如,我为会话设置一个整数值:
function Test(c *gin.Context){
session:= sessions.Default(c)
session.Set("mysession",123)
session.Save()
}
Run Code Online (Sandbox Code Playgroud)
在另一个控制器中,我可以通过 获得此会话session.Get("mysession")。
但如果我设置地图或结构。我只能在同一个控制器中获取会话。这里出了什么问题?
我已经阅读了十几个不同的博客,以及阅读msdn示例,他们只是不适合我.
最终我要做的是自动将数据库从我们的生产实例移动到我们的开发实例,或者另一个方向.
我采取的方法是:
我坚持1,我不明白为什么.我读过的所有内容都声称这应该有效.
注意:我已设置dbName为要还原到的数据库.我也设置了restore.Database = dbName,名称空间restore中的Restore类的实例在哪里smo.
mdf.LogicalFileName = dbName;
mdf.PhysicalFileName = String.Format(@"{0}\{1}.mdf", server.Information.MasterDBPath, dbName);
ldf.LogicalFileName = dbName + "_log";
ldf.PhysicalFileName = String.Format(@"{0}\{1}.ldf", server.Information.MasterDBPath, dbName);
restore.RelocateFiles.Add(mdf);
restore.RelocateFiles.Add(ldf);
restore.SqlRestore(server);
Run Code Online (Sandbox Code Playgroud)
这是我得到的例外:
无法覆盖文件'D:\ MSSQL.MIQ_Dev\MSSQL.2\MSSQL\Data\MIQDesign2Detach.mdf'.数据库'MIQDesignTest2'正在使用它.
文件'MIQDesign'无法恢复为'D:\ MSSQL.MIQ_Dev\MSSQL.2\MSSQL\Data\MIQDesign2Detach.mdf'.使用WITH MOVE标识文件的有效位置.
无法覆盖文件'D:\ MSSQL.MIQ_Dev\MSSQL.2\MSSQL\Data\MIQDesign2Detach.ldf'.数据库'MIQDesignTest2'正在使用它.
文件'MIQDesign_log'无法恢复为'D:\ MSSQL.MIQ_Dev\MSSQL.2\MSSQL\Data\MIQDesign2Detach.ldf'.使用WITH MOVE标识文件的有效位置.
在规划RESTORE语句时发现了问题.以前的消息提供详情.
RESTORE DATABASE异常终止.
为什么要尝试覆盖原来的mdf?是不是RelocateFiles应该指定您希望将其保存到不同的物理文件名?
我正在使用visual studio 2010
frmMain有一个"注册"按钮,调用另一种形式newReg
这是frmMain调用第二种形式的按钮的代码.问题是MessageBox("So Far So Good")永远不会被调用.在dialogResult似乎没有得到认可.
private void btnRegisterNew_Click(object sender, EventArgs e)
{
// newReg Constructor Call
newReg = new frmRegisterNew();
// show form
newReg.Show();
if (newReg.DialogResult.Equals(DialogResult.OK))
{
MessageBox.Show ("So Far So Good");
}
}
Run Code Online (Sandbox Code Playgroud)
第二种形式有一些要填写的字段和一个按钮"注册".我已经dialogResult在属性窗口中将此按钮设置为"ok",我认为也在代码中.单击第二种形式的"注册"按钮时,它会检查输入,尝试更新数据库并在成功时关闭.这是一段代码:
dbConnection db = new dbConnection();
db.dbConnect();
if (db.dbRegisterVehicle(txtNewReg.Text, txtNewMake.Text, txtNewModel.Text, txtNewColour.Text, OwnerID))
{
// if insert worked close
this.DialogResult = DialogResult.OK;
this.Close();
}
db.dbDisconnect();
Run Code Online (Sandbox Code Playgroud)
我确定要尝试什么,或者我可能会看到什么.
我正在用C++编写一个程序,使用我自己的头文件.
main.cpp中
#include<iostream>
#include"operation.h"
using namespace std;
main()
{
int a;
cout <<"Enter the value a";
cin>>a;
//class name add
//obj is object of add
add obj;
obj.fun(a);
}
Run Code Online (Sandbox Code Playgroud)
operation.h
class add
{
void fun(int b)
{
int c,d=10;
c=d+b;
cout<<"d="<<d;
}
}
Run Code Online (Sandbox Code Playgroud)
当我在Linux中使用G ++编译时,它显示以下错误:
->expected ";" before obj
->obj not declared in this scope
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?为什么会这样?
我正在寻找一种优雅的方法来确定哪个元素在C++ ptr数组中出现次数最多(模式).
例如,在
{"pear", "apple", "orange", "apple"}
Run Code Online (Sandbox Code Playgroud)
"apple"元素是最常见的元素.
我以前的尝试失败编辑:数组已经排序.
int getMode(int *students,int size)
{
int mode;
int count=0,
maxCount=0,
preVal;
preVal=students[0]; //preVall holds current mode number being compared
count=1;
for(int i =0; i<size; i++) //Check each number in the array
{
if(students[i]==preVal) //checks if current mode is seen again
{
count++; //The amount of times current mode number has been seen.
if(maxCount<count) //if the amount of times mode has been seen is more than maxcount
{
maxCount=count; //the larger …Run Code Online (Sandbox Code Playgroud) 我修复了代码并更新了,但现在我不知道在哪里放置构造函数:
private JPanel panel;
public RollButton(JPanel panel){
this.panel = panel;
}
Run Code Online (Sandbox Code Playgroud)
我查看了一些放置构造函数的示例,看起来它放在我的RollButton类周围,但我试图将它放在多个地方并且在多个地方,但我似乎无法做到正确.
码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Random;
public class DiceRollGUI {
public static JLabel label;
public static JFrame frame;
public static JPanel panel;
private static JButton button;
private static JButton buttonRollDie;
private static JLabel diceRoll;
public static void main (String[] args) {
JFrame frame = new JFrame("Dice Roll GUI");
JPanel contentPanel = new JPanel(new GridLayout(0,2,5,10));
button = new JButton("Roll");;
frame.setVisible(true);
frame.setResizable(false);
frame.setSize(750, …Run Code Online (Sandbox Code Playgroud) 出于某种原因,评估者if isEven(n)发出错误......你能发现代码的问题吗?
function isEven(value) {
//value = Number(value);
if (value%2 == 0)
return true;
else
return false;
}
function testCondition {
if isEven(n) {
}
else {
}
}
Run Code Online (Sandbox Code Playgroud) c++ ×3
javascript ×3
algorithm ×1
arrays ×1
button ×1
c ×1
c# ×1
c++11 ×1
closures ×1
constructor ×1
debouncing ×1
dialogresult ×1
dictionary ×1
go ×1
go-gin ×1
java ×1
mapbox ×1
mode ×1
pointers ×1
raspberry-pi ×1
session ×1
smo ×1
std ×1
swing ×1
web ×1