以下是我的jsp代码的一部分:
${cForm.cId} <!-- I can see this value displayed correctly --%>
<%! String i = ${cForm.cId}; %>
<td class="value">
<img src="/supportcenter/cServlet?sampleImg=<%=i %>" width="300px" />
</td>
Run Code Online (Sandbox Code Playgroud)
cForm是我的 java 对象文件,我可以看到浏览器中正确显示的${cForm.cId}.
但是,当我想将值分配给字符串i变量时,我不断遇到failed to compile :jsp错误。
好心提醒。
这是我写的示例代码,
public static void main(String []args){
String inputString = "apple";
char a = inputString[2]; //one
System.out.println(inputString[2]); //two
}
Run Code Online (Sandbox Code Playgroud)
一和二都给我一个错误,说Array type expected; found: 'java.lang.String'我做错了什么?如何访问字符串中的特定索引?
我希望能够通过引用对象的名称而不是对象本身来更改数据框的单元格,但是当我尝试这样做时,会导致 warning could not find function "eval<-"。
我可以使用下面的代码更改标准数据框的单元格:
my_object = tibble(x = c("Hello", "Goodbye"),
y = c(1,2))
object[2,1] <- "Bye"
Run Code Online (Sandbox Code Playgroud)
但在使用对象的名称时我很难做同样的事情。我可以使用对象的名称来评估该对象并提取相关的单元格:
object_name = "my_object"
eval(sym(object_name))[2, 1]
Run Code Online (Sandbox Code Playgroud)
但我无法为该对象分配新变量(错误could not find function "eval<-":):
eval(sym(object_name))[2, 1] <- "Bye"
Run Code Online (Sandbox Code Playgroud) 我在我使用的程序中找到了一些代码:
PWSTR myWchar = NULL;
WCHAR *p = myWchar = new WCHAR[4];
Run Code Online (Sandbox Code Playgroud)
我如何读取带有两个等号的行?
它是如何计算的?
A:
myWchar = new WCHAR[4];
WCHAR *p = myWchar
Run Code Online (Sandbox Code Playgroud)
或乙:
WCHAR *p = myWchar ;
myWchar = new WCHAR[4];
Run Code Online (Sandbox Code Playgroud) 我有结构aa,我正在尝试运行这样的代码:
aa * b = new aa;
aa * c = new aa;
c=b;
delete (b);
c.useSomeFunction
Run Code Online (Sandbox Code Playgroud)
我可以使用c破坏后指向的对象b吗?
在以下情况下的相同问题:
aa * b = new aa;
aa * c ;
c=b;
delete (b);
c.useSomeFunction
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
std::map<size_t,Cell&> m_cellMap;
Run Code Online (Sandbox Code Playgroud)
当Cell定义如下:
class Cell
{
public:
Cell(int x = 0,int y = 0) : m_x(x),m_y(y) { }
private:
int m_x;
int m_y;
/// class members and methods
};
Run Code Online (Sandbox Code Playgroud)
我不能编译下面的代码:
Cell c;
m_cellMap[0] = c;
Run Code Online (Sandbox Code Playgroud)
得到错误:出了error C2101: '&' on constant
什么问题?如何解决?
谢谢
我正在学习Ada,目前的课程是关于阵列的.考虑以下计划;
procedure Main is
type T_Bool is array (Boolean) of Integer;
type T_Intg is array (Integer range 1 .. 2) of Integer;
A1 : T_Bool := (others => 0);
A2 : T_Intg := (others => 0);
begin
-- None of these statements work
A2 := A1;
A2 (1 .. 2) := A1 (false .. true);
A2 := A1 (Boolean'First .. Boolean'Last);
end Main;
Run Code Online (Sandbox Code Playgroud)
根据Adacore大学的导师,只要长度相同,就可以将值从一个数组复制到另一个数组.在代码片段中,为什么不分配具有相同大小但不同索引方法的数组,尽管长度相同?
复制这个的正确方法是什么?是循环遍历Boolean类型范围内的所有索引并复制相应的数组索引还是另一种聪明的方法呢?
我有大约4个int数组,需要计算它们的长度,分配给它们然后填充.我试图通过使用带参数的函数来稀释代码,而不是重复4次长计算,但我似乎无法通过将数组指定为参数来设置长度.我尝试过类似下面的代码:
for(int i=0; i<4; i++)
if(i==0) SetLength(array1);
else if(i==1) SetLength(array2);
else if(i==2) SetLength(array3);
else if(i==3) SetLength(array4);
SetLength(int[] array)
{
//calculations for length here
//int result=...;
array = new int[result];
//getting info for populating the array
for(int i=0; i<result; i++)
array[i]=some_value[i];
}
Run Code Online (Sandbox Code Playgroud)
除了长度分配部分之外,大多数代码似乎都有效.有任何想法吗?
考虑以下代码:
class vector{
// ...
vector(int size){ /*...*/ };
vector& operator= (const vector& other){
// ...
}
};
int main(){
vector v1(5), v2(10);
v1 = v2;
}
Run Code Online (Sandbox Code Playgroud)
我operator =应该在这做什么?v1没有足够的容量存储元素v2.从我的角度来看,它可以将自身重新初始化为10的容量,并复制其他向量的元素或抛出异常.我通常选择前一种方法,但越来越多地经常看到后者.哪一个是正确的?
当我尝试将值分配给多级哈希时
use strict;
# multi step before following code
$res{cccc}{1}{sense} = '+'; # no problem
my $ttsid = 'NZAEMG01000001';
$res{$ttsid}{1}{sense} = '+'; # no problem
$ttsid = 'NZAEMG01000001.1';
$res{$ttsid}{1}{sense} = '+'; # no problem
print "before sid is $sid\n"; # print out NZ_AEMG01000001t1
Run Code Online (Sandbox Code Playgroud)
在这一步,程序运行良好
$res{$sid}{1}{sense} = '+'; # even this gets problem too
Run Code Online (Sandbox Code Playgroud)
但是,当我将这一行添加到程序中时,我收到了错误
Can't use string ("57/128") as a HASH ref while "strict refs" in use
Run Code Online (Sandbox Code Playgroud)
用以下方法测试一下
$sid = 'placement'; # result
$res{$sid}{1}{sense} = '+';
Run Code Online (Sandbox Code Playgroud)
这没问题.所以在我看来,这条线
$sid = 'placement'; …Run Code Online (Sandbox Code Playgroud)