我是C++编程的新手,显然缺少一些东西.在下面的代码中,编译器似乎没有识别出这一行:lengths[counter] = findDups(crtLine);
我收到一个错误:变量"length"已设置但未使用.我无法弄清楚为什么它不能识别这条线,当names[counter] = getNameOnly(crtLine)
它完美地工作并且它基本上是相同的格式.任何洞察这个问题的人都表示赞赏!
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
string getNameOnly (string line) {
return line.substr(0, line.find(' '));
}
int findDups (string line) {
string lnCpy = line;
sort(lnCpy.begin(), lnCpy.end());
int i = 0;
int dups = 0;
int j = 1;
int len = lnCpy.length();
while (j < len) {
if (lnCpy.at(i) == lnCpy.at(j))
dups++;
i++;
j++;
}
if (dups != 0)
return 0;
else
return lnCpy.length();
} …
Run Code Online (Sandbox Code Playgroud) 我有一个带有加载位图图像的RelativeLayout,使用来自Pragmatic Bookshelf的Touch V2示例 - http://media.pragprog.com/titles/eband3/code/Touchv2/src/org/example/touch/Touch.java
我在onclicklistener中添加了一个单独的按钮,单击该按钮将从图库中加载图像.在活动结果上,图像作为位图加载到RelativeLayout中:
public void getPictureFromFile(Uri targetUri){
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = scale(getContentResolver()
.openInputStream(targetUri));
workinprogress = BitmapFactory.decodeStream(
getContentResolver().openInputStream(targetUri),
null, options);
view.setImageBitmap(workinprogress);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
点击下一个按钮,我使用以下方法抓取relativelayout的图像:
thepicture.buildDrawingCache(true);
Bitmap bm = Bitmap.createBitmap(thepicture.getDrawingCache());
Run Code Online (Sandbox Code Playgroud)
对于第一张图片,这个过程非常有效.当我再次加载另一个图像时,传递的位图仍然与原始位图相同.我在getDrawingCache()之前尝试了thepicture.invalidate()和thepicture.resetDrawableState(),但似乎都没有将图像更新为新加载的图片,尽管框架布局显示正确的图像.
对于我需要为我加载的第二个图像实现的刷新drawingCache,是否有一些我不明白的事情?
我正在使用一个两次调用同一个类并抛出错误的脚本:
Fatal: Cannot redeclare class urlConverter (/var/www/core/cache/includes/elements/modsnippet/23.include.cache.php:14)
Run Code Online (Sandbox Code Playgroud)
我尝试将以下代码放入:
if( !class_exists( 'urlConverter', false ) )
{
$urlConverter = new urlConverter( $modx );
}
Run Code Online (Sandbox Code Playgroud)
但是,我正在使用的CMS正在报告错误500并且无法在日志中看到它为什么会抛出该错误.
有谁知道如何检查该类是否已被正确声明?
编辑:
我正在使用CMS,因此Class被放在一个Snippet而不是实际文件中.这就是他们称之为片段的方式:
$data['viewonlinelink'] = $this->modx->runSnippet( 'urlConverter', array(
'action' => 'encrypt',
'string' => http_build_query( $string ) ) );
Run Code Online (Sandbox Code Playgroud)
我需要第二次打电话来获得不同的结果.
EDIT2:
这是urlConverter:
<?php
class urlConverter {
public $modx;
public function __construct( modX &$modx )
{
$this->modx =& $modx;
}
public function action( $scriptProperties )
{
return $this->$scriptProperties['action']( $scriptProperties['string'] );
}
private function encrypt( $str )
{
return $str; …
Run Code Online (Sandbox Code Playgroud) 我有以下方法返回void,我需要在另一个也返回void的方法中使用它.我可以这样做吗?
public void doSomething(){}
public void myMethod()
{
return doSomething();
}
Run Code Online (Sandbox Code Playgroud)
感谢您的所有评论,但让我更具体
我只有doSomething
在事情发生时,否则我做其他事情
public void doSomething(){}
public void myMethod()
{
for(...)
if(somethingHappens)
{
doSomething();
return;
}
doOtherStuff();
}
Run Code Online (Sandbox Code Playgroud)
而不是上面的代码,我可以return doSomething();
在if语句中写入吗?
我有一个带有一些内部变量的C类.它有一个嵌套的类N,它想要访问C中的变量.虽然C有一些静态方法和变量,但C和N都不是静态的.当我尝试从NI访问C中的非静态变量时,得到波浪线下划线和消息"无法在静态上下文中访问非静态字段[fieldname]".
这似乎与嵌套类有关,因为我可以从封闭类本身访问变量.
ReSharper建议我使_t静态,但这不是一个选项.我该如何处理?
public sealed partial class C
{
string _t;
class N
{
void m()
{
_t = "fie"; // Error occurs here
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用i18n_patterns
Django 1.4 的新功能:
from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
admin.autodiscover()
urlpatterns += i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
)
Run Code Online (Sandbox Code Playgroud)
它适用于所有活动语言:
/en/admin/ # Ok
/es/admin/ # Ok
Run Code Online (Sandbox Code Playgroud)
但这失败了:
/admin/ # 404 Not found
Run Code Online (Sandbox Code Playgroud)
如何避免404错误并重定向到所请求URL的语言前缀版本(不仅仅是管理面板)?
是编写自定义中间件的解决方案吗?为什么在Django中默认不会出现这种情况?
我们如何使用 sed 获取 " Install ID:
" 和后面第一个空格之间的 4 个字符XKCD
,基本上我想XKCD
从中提取 " " 字符串
Install ID: XKCD (8426200,8179503)
Run Code Online (Sandbox Code Playgroud)
我尝试使用 -
echo "Install ID: XKCD (8426200,8179503)" | sed -n 's/^.*ID:\(.*\)*$/\1/p'
Run Code Online (Sandbox Code Playgroud)
但这给了我“ XKCD (8426200,8179503)
”而不是仅仅XKCD
。我无法弄清楚如何处理空间部分。
我正在编写一个Linux内核模块,需要在链接上/下时收到通知,现在我已经读过我可以打开netlink socket
并监听RTMGRP_LINK
(网络接口创建/删除/上/下事件)组播组,但这是从用户空间使用的......任何人都知道如何从内核空间捕获这个中断?我正在使用内核2.6.35
我正在创建一个UIBarButtonItem并将其添加到我的导航栏,如下所示:
(void)viewDidLoad {
...
// Add the refresh button to the navigation bar
UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
[refreshButton setFrame:CGRectMake(0,0,30,30)];
[refreshButton setImage:[UIImage imageNamed:@"G_refresh_icon.png"] forState:UIControlStateNormal];
[refreshButton addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *refreshBarButton = [[[UIBarButtonItem alloc] initWithCustomView:refreshButton] autorelease];
self.navigationItem.leftBarButtonItem = refreshBarButton;
}
Run Code Online (Sandbox Code Playgroud)
它在我运行时看起来是正确的,但我可以通过点击导航栏从x = 0到大约100来选择条形按钮项目.如何调整可选区域的宽度为30像素?
我想从asp.net jquery html客户端应用程序向服务器端发送请求.
服务器端代码将执行任务,一旦完成,它将输出一些jpeg文件.
问题是我想在jpeg准备就绪时自动通知Web应用程序.
我每隔2秒就拨打一次电话,而且轮询方式太多了.
我想以某种方式发送一个调用服务器然后我想得到jpegs在目录中的响应.
我正在使用c#asp.net v4