好的 - 我几乎不好意思在这里张贴这个(如果有人投票结束我会删除),因为这似乎是一个基本问题.
这是在C++中舍入到数字的倍数的正确方法吗?
我知道还有其他与此相关的问题,但我特别感兴趣的是知道在C++中执行此操作的最佳方法是什么:
int roundUp(int numToRound, int multiple)
{
if(multiple == 0)
{
return numToRound;
}
int roundDown = ( (int) (numToRound) / multiple) * multiple;
int roundUp = roundDown + multiple;
int roundCalc = roundUp;
return (roundCalc);
}
Run Code Online (Sandbox Code Playgroud)
更新:对不起我可能没有明确意图.这里有些例子:
roundUp(7, 100)
//return 100
roundUp(117, 100)
//return 200
roundUp(477, 100)
//return 500
roundUp(1077, 100)
//return 1100
roundUp(52, 20)
//return 60
roundUp(74, 30)
//return 90
Run Code Online (Sandbox Code Playgroud)
编辑:感谢所有的回复.这是我的目的:
int roundUp(int numToRound, int multiple)
{
if(multiple == 0)
{
return numToRound;
} …
Run Code Online (Sandbox Code Playgroud) 哈希和MAC(消息认证码)之间有什么区别?
根据他们的定义,他们似乎具有相同的功能.
有人可以解释一下有什么区别吗?
我有一个缩放到适合的图像.从缩放的图像中,用户正在选择矩形.
然后我根据这个选择重新绘制:
gc.drawImage(imageDisplayed, minX, minY, width, height, imageDisplayed.getBounds().x, imageDisplayed.getBounds().y, imageDisplayed.getBounds().width, imageDisplayed.getBounds().height );
Run Code Online (Sandbox Code Playgroud)
所以现在我希望能够从缩放和缩放的图像中获得原始坐标.它是否正确?:
public Coordinate GetScaledXYCoordinate(int oldX, int oldY, int width, int height, int scaledWidth, int scaledHeight)
{
int newX = (int)(oldX * width)/scaledWidth;
int newY = (int)(oldY * height)/scaledHeight;
Coordinate retXY = new Coordinate(newX, newY);
return retXY;
}
public Coordinate GetZoomedXYCoordinate(int oldX, int oldY, int startX, int endX, int startY, int endY,
int width, int height,int scaledWidth, int scaledHeight)
{
// First get x,y after scaling
Coordinate xy = …
Run Code Online (Sandbox Code Playgroud) 可能重复:
我们如何使用Win32程序检查文件是否存在?
检查文件存在的最佳方法是:
选项1:
GetFileAttributes("C:\\MyFile.txt"); // from winbase.h
if(0xffffffff == GetFileAttributes("C:\\MyFile.txt"))
{
//File not found
}
Run Code Online (Sandbox Code Playgroud)
选项2:
std::string fileName("C:\\MyFile.txt" );
ifstream fin( fileName.c_str() );
if( fin.fail() )
{
//File not found
}
Run Code Online (Sandbox Code Playgroud)
另外如果您认为选项1是更好的方法,您能告诉我如何定义0xffffffff
为常量(我不想使用#define)
谢谢
根据以下要求保护REST Web API的最佳方法是什么?该系统有一个Angular JS前端,其中包含在ASP.net中实现的REST API.
我相信Oauth将是我最好的选择.
这是在C#中获取特定Exception名称的最佳方法:
ex.GetType().ToString()
Run Code Online (Sandbox Code Playgroud)
它位于通用异常处理程序中:
catch (Exception ex)
Run Code Online (Sandbox Code Playgroud) 在下面的代码片段中,我想验证第一个异步方法中的字段.
如果它们无效,我想立即向用户返回错误.
我怎么做?
var form = new formidable.IncomingForm();
async1.series([
function (callback) {
form.parse(req);
form.on('field', function (name, val) {
// Get the fields
});
form.on('fileBegin', function (name, file) {
if (file.name !== "") {
file.path = __dirname + '/upload/' + file.name;
}
});
callback();
},
function (callback) {
form.on('file', function (name, file) {
try {
// Do something with the file using the fields retrieved from first async method
}
catch (err) {
logger.info(err);
}
});
callback();
}
], function (err) …
Run Code Online (Sandbox Code Playgroud) 在C#中编辑字符串中字符的最简洁方法是什么?
C++中C#的等价物是什么:
std::string myString = "boom";
myString[0] = "d";
Run Code Online (Sandbox Code Playgroud) 有人最近问了一个关于Ghost设计模式的问题 - 我以前没见过.
什么是Ghost设计模式以及如何实现?我只能在网上找到它的片段.
如果我使用以下内容获取所有已连接驱动器的列表:
available_drives = ['%s:' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)]
Run Code Online (Sandbox Code Playgroud)
如何获取已连接驱动器的UNC路径?
os.path
只是返回z:\
而不是\share\that\was\mapped\to\z
c++ ×3
.net ×2
c# ×2
algorithm ×1
angularjs ×1
asp.net ×1
async.js ×1
coordinates ×1
cryptography ×1
exception ×1
file-io ×1
formidable ×1
hash ×1
image ×1
java ×1
javascript ×1
node.js ×1
oauth ×1
python ×1
python-2.7 ×1
reflection ×1
rounding ×1
security ×1
string ×1
swt ×1
terminology ×1
unc ×1
windows ×1