问题列表 - 第13552页

如何在std :: vector中找到元素位置?

我需要在std :: vector中找到一个元素位置,用它来引用另一个向量中的元素:

int find( const vector<type>& where, int searchParameter )
{
    for( int i = 0; i < where.size(); i++ ) {
       if( conditionMet( where[i], searchParameter ) ) {
           return i;
       }
    }
    return -1;
}
// caller:
const int position = find( firstVector, parameter );
if( position != -1 ) {
    doAction( secondVector[position] );
}
Run Code Online (Sandbox Code Playgroud)

但是vector::size()返回size_t对应于unsigned不能直接存储的整数类型-1.当使用size_t而不是int作为索引时,如何表示在向量中找不到元素?

c++ search stl vector

35
推荐指数
4
解决办法
12万
查看次数

单元测试程序集的app.config:如何使appsettings'文件'属性工作?

我需要在单元测试中从appsettings部分(在app.config中定义)中读取设置.我们在这个项目中使用mstest.

说这是app.config:

<configuration>
 <appSettings>
   <add key="MyAppSetting" value="MyAppSettingValue"/>
 </appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

这是相应的测试,它通过了这个设置:

[TestClass]
public class ConfigurationTests
{
    [TestMethod]
    public void can_read_appsettings()
    {
      string value = ConfigurationManager.AppSettings.Get("MyAppSetting");
      Assert.AreEqual("MyAppSettingValue", value);
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试将appSettings部分移动到custom.config文件时,此测试失败.

这就是我的app.config文件现在的样子:

<configuration>
 <appSettings file='Custom.config' />
</configuration>
Run Code Online (Sandbox Code Playgroud)

我将Custom.config文件添加到我的项目中(使用构建操作'始终复制'):

 <appSettings>
   <add key="MyAppSetting" value="MyAppSettingValue"/>
 </appSettings>
Run Code Online (Sandbox Code Playgroud)

在控制台应用程序中执行相同操作时,这是有效的.有没有办法在单元测试装配中使这个工作?

.net mstest assemblies app-config

6
推荐指数
1
解决办法
7303
查看次数

在xmlhttp.onreadystatechange函数中,如何传递我要编辑的ID的名称?

这是我的代码.查看已注释掉的行.当元素id(这是一个跨度)是硬编码时,它可以工作.当通过连接传递给stateChanged的变量创建id时,它不起作用.我不允许将变量传递给stateChanged吗?怎么了?

function multiplePassportPoints(id, counter)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="addmorepoints.php"; 
url=url+"?id="+id+"&c="+counter;
url=url+"&sid="+Math.random();

xmlhttp.onreadystatechange=stateChanged(id,counter);
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged(id, counter) 
{
  if (xmlhttp.readyState==4)
  {
    //THIS WORKS (assuming id is 99 and counter is 5:
    //document.getElementById("99_5").innerHTML += xmlhttp.responseText; 

    //BUT I NEED IT TO WORK LIKE THIS:
    document.getElementById(studentID+"_"+counter).innerHTML += xmlhttp.responseText; 
  }
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

xmlhttprequest

3
推荐指数
1
解决办法
1万
查看次数

如何使MSBuild自动将所有间接引用复制到output(bin)文件夹

SUBJ.

"自动"在这里至关重要.不得复制GAC的引用.

我见过例如VS2008.NET:获取引用项目的依赖项以复制到主项目的bin文件夹,这对我来说并不重要.我希望自动复制所有依赖项.

.net msbuild build-automation dependencies reference

27
推荐指数
1
解决办法
9449
查看次数

如何设置DropShadowEffect的不透明度?

我有一个带边框的WPF项目使用以下样式.计划是当鼠标移过边界时使发光效果淡入淡出,并在离开时淡出淡出效果.

<Style x:Key="BorderGlow" TargetType="Border">
    <Style.Resources>
        <Storyboard x:Key="GlowOn">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(DropShadowEffect.Opacity)">
                <SplineDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="GlowOff">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(DropShadowEffect.Opacity)">
                <SplineDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Style.Resources>

    <Setter Property="CornerRadius" Value="6,1,6,1" />
    <Setter Property="BorderBrush" Value="{StaticResource SelectedBorder}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Background" Value="{StaticResource DeselectedBackground}" />
    <Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
    <Setter Property="TextBlock.Foreground" Value="{StaticResource SelectedForeground}" />

    <Setter Property="RenderTransform">
        <Setter.Value>
            <RotateTransform Angle="90"/>
        </Setter.Value>
    </Setter>

    <Setter Property="Effect">
        <Setter.Value>
            <DropShadowEffect ShadowDepth="0" BlurRadius="8" Color="#FFB0E9EF"/>
        </Setter.Value>
    </Setter>

    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">

            <Trigger.EnterActions>
                <BeginStoryboard Storyboard="{StaticResource GlowOn}"/>
            </Trigger.EnterActions>

            <Trigger.ExitActions>
                <BeginStoryboard …
Run Code Online (Sandbox Code Playgroud)

wpf animation effects opacity storyboard

6
推荐指数
1
解决办法
1万
查看次数

如何用PHP获取文件内部的文件?

a.php只会:

<?php

...

?>
Run Code Online (Sandbox Code Playgroud)

如何知道自己内的目录?

编辑 在Windows上,如何将"\"更改为"/"?

php file

0
推荐指数
1
解决办法
160
查看次数

你如何把重点放在Swing的Textfield上?

我在Java中使用Swing创建了一个表单.在表单中我使用了一个文本字段,每当我按下键时我都必须设置焦点.如何在Java中设置焦点在特定组件上?

java swing focus

44
推荐指数
5
解决办法
7万
查看次数

从现有的MySQL数据库中反向设计SQLAlchemy声明性类定义?

我有一个预先存在的mysql数据库,包含大约50个表.

而不是为每个表手动编写一个声明式样式SqlAlchemy类(如此处所示),是否有一个工具/脚本/命令我可以针对mysql数据库运行,它将为数据库中的每个表生成声明式样式的python类?

仅以一个表为例(将为所有50个理想情况生成),如下所示:

+---------+--------------------+
| dept_no | dept_name          |
+---------+--------------------+
| d009    | Customer Service   |
| d005    | Development        |
| d002    | Finance            |
| d003    | Human Resources    |
| d001    | Marketing          |
| d004    | Production         |
| d006    | Quality Management |
| d008    | Research           |
| d007    | Sales              |
+---------+--------------------+
Run Code Online (Sandbox Code Playgroud)

是否有工具/脚本/命令可以生成包含以下内容的文本文件:

from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Department(Base):
   __tablename__ = 'departments'

   dept_no = Column(String(5), primary_key=True) …
Run Code Online (Sandbox Code Playgroud)

python mysql sqlalchemy

24
推荐指数
4
解决办法
8442
查看次数

查找表的列的创建日期/时间

如何查询SQL Server以获取SQL Server 2005表列的创建日期?

我试图sp_columns [tablename]获取该信息,但创建日期未包含在此存储过程中.

如何才能做到这一点?

sql t-sql sql-server sql-server-2005

8
推荐指数
2
解决办法
4万
查看次数

将hex转换为二进制

我有ABC123EFFF.

我想拥有001010101111000001001000111110111111111111(即二进制代表,例如42位数和前导零).

怎么样?

python string binary hex string-formatting

96
推荐指数
10
解决办法
25万
查看次数