考虑以下.我有两个导出的常量如下:
// somefile.h
extern const double cMyConstDouble;
extern const double cMyConstDouble2;
Run Code Online (Sandbox Code Playgroud)
和
// somefile.cpp
const double cMyConstDouble = 3.14;
const double cMyConstDouble2 = 2.5*cMyConstDouble;
Run Code Online (Sandbox Code Playgroud)
现在引用这些常量来定义两个静态(局部可见)常量:
// someotherfile.cpp
#include "somefile.h"
static const double cAnotherDouble = 1.1*cMyConstDouble;
static const double cAnotherDouble2 = 1.1*cMyConstDouble2;
printf("cAnotherDouble = %g, cAnotherDouble2 = %g\n",
cAnotherDouble, cAnotherDouble2);
Run Code Online (Sandbox Code Playgroud)
产生以下输出:
cAnotherDouble = 3.454, cAnotherDouble2 = 0
Run Code Online (Sandbox Code Playgroud)
为什么第二双0?我正在使用.NET 2003 C++编译器(13.10.3077).
我有一个程序,允许用户输入一个级别号,然后它播放该级别:
char lvlinput[4];
std::cin.getline(lvlinput, 4)
char param_str[20] = "levelplayer.exe "
strcat_s(param_str, 20, lvlinput);
system(param_str);
Run Code Online (Sandbox Code Playgroud)
并且级别数据存储在文件夹\ 001,\ 002,\ 003等等中.但是,我无法判断用户是否输入了三位数,即:1,01或001.并且所有文件夹列为三位数字.我不能只检查lvlinput字符串的长度,因为它是一个数组,所以我怎样才能确保用户输入三位数?
我一直在尝试使用 mongodb 并插入一些数据,但出现错误。这是代码。
const MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/TodoApp', (err, db) => {
if (err) {
return console.log('Unable to connect to MongoDB server');
}
console.log('Connected to MongoDB server');
db.collection('Users').insertOne({
name: 'Andrew',
age: 25,
location: 'Philadelphia'
}, (err, result) => {
if (err) {
return console.log('Unable to insert user', err);
}
console.log(result.ops);
});
db.close();
});
Run Code Online (Sandbox Code Playgroud) 我正在使用Win32函数GetEnvironmentVariable来检索我刚刚创建的变量的值.我正在运行Windows XP和VC++ 2005.如果我从Visual Studio中运行程序,它找不到新的变量.如果我从命令提示符运行它,它会.我重新启动VC++但结果相同.我甚至重新启动了Visual Studio的所有实例,但仍然是同样的问题.如果我重新启动电脑可能会得到解决,但我很好奇为什么会这样.这是我正在使用的代码:
#define BUFSIZE 4096
#define VARNAME TEXT("MY_ENV_NAME")
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR chNewEnv[BUFSIZE];
DWORD dwEnv = ::GetEnvironmentVariable(VARNAME, chNewEnv, BUFSIZE);
if (dwEnv == 0)
{
DWORD dwErr = GetLastError();
if(dwErr == ERROR_ENVVAR_NOT_FOUND)
{
printf("Environment variable does not exist.\n");
return -1;
}
}
else
{
printf(chNewEnv);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我用必须存在的内容替换MY_ENV_NAME,例如TEMP,它会按预期工作.有任何想法吗?谢谢.
这是我的addCard函数,它将一个playCard作为参数,然后将其自身的地址移交给一个分配给playCard对象的指针数组.
void cardHand::addCard(playingCard card) {
theHand[nElems++] = &card;
} // addCard()
Run Code Online (Sandbox Code Playgroud)
现在,当我运行我的程序时它运行正常,但在调用析构函数时崩溃.
cardHand::~cardHand() {
for(int c = 0;c<MAX;c++) {
if(theHand[c] != NULL)
delete theHand[c]; // here is the problem
}
delete [] theHand;
} // class destructor
Run Code Online (Sandbox Code Playgroud)
它崩溃是因为我只是在addCard函数中移交了playingCard对象的地址.它应该是指针吗?
我正在索引文件的元数据,我的映射看起来像这样:
curl -XPUT "http://localhost:9200/myapp/" -d '
{
"mappings": {
"file": {
"properties": {
"name": {
"type": "string", "index": "not_analyzed"
},
"path": {
"type": "string", "index": "not_analyzed"
},
"user": {
"type": "string", "index": "not_analyzed"
}
}
}
}
}
'
Run Code Online (Sandbox Code Playgroud)
还有其他一些领域,但它们与这个问题无关.这里'name'是文件的名称,'path'是文件的路径,user是该文件的所有者.索引数据时看起来像:
{ name: 'foo', path: '/', user: 'dude' }
{ name: 'bar', path: '/subfolder/', user: 'dude' }
{ name: 'baz', path: '/', user: 'someotherdude' }
Run Code Online (Sandbox Code Playgroud)
我的问题是如何构建我的查询,以便我可以在给定路径和用户的情况下进行文件夹列表.因此,搜索用户'dude'和路径'/'应该导致'foo'.
我有以下代码:
let request = require('request');
let fs = require('fs');
request.get('http://localhost:8080/report.rtf')
.pipe(fs.createWriteStream(__dirname + '/savedDoc.rtf'));
Run Code Online (Sandbox Code Playgroud)
它运行良好,但前提是文档从给定的 URL 成功下载。但是,如果有任何 HTTP: 403、404 或任何其他错误,则会保存一个长度为零的空文件!
我怎么能.pipe()只在 HTTP: 200 响应的情况下而不使用任何额外的 HEAD 请求?应该可以一口气搞定!
当我调用以下方法时,执行两个返回,我无法弄清楚原因.
def Build(self, name = None):
if self.buildData:
try:
installData = self.buildData.Build(name)
return BuildResult(True, installData)
except:
pass
else:
Log("Application has no <build> data")
return BuildResult(False, None)
Run Code Online (Sandbox Code Playgroud)
这是怎么回事:
c++ ×4
node.js ×2
const ×1
destructor ×1
double ×1
extern ×1
javascript ×1
mongodb ×1
node-streams ×1
npm-request ×1
pointers ×1
python ×1
return-value ×1
string ×1