我用Java编写了以下代码,运行正常:
public class test {
public static void main(String[] args) {
final String s1 = "s1" ;
final String s2 = "s2" ;
String s = "s1" ;
switch(s) {
case s1 : System.out.println("s1") ;
break ;
case s2 : System.out.println("s2") ;
break ;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我写下面的代码时:
public class test {
public static void main(String[] args) {
final String s1 = "s1".toString() ;
final String s2 = "s2".toString() ;
String s = "s1" ;
switch(s) {
case s1 : …Run Code Online (Sandbox Code Playgroud) 假设我有一个C结构定义如下:
typedef struct servData {
char max_word[MAX_WORD];
char min_word[MAX_WORD];
int word_count ;
} servSendData ;
Run Code Online (Sandbox Code Playgroud)
其中'MAX_WORD'可以是任何值.现在,如果我有这个结构的实例:
servSendData myData ;
Run Code Online (Sandbox Code Playgroud)
如果我填充此实例然后通过网络发送它,考虑到我希望我的服务器以及客户端在64位系统或32位系统上运行,是否会出现任何可移植性问题.
我将发送和接收数据如下:
//server side
strcpy(myData.max_word, "some large word") ;
strcpy(myData.min_word, "small") ;
myData.word_count=100 ;
send(sockFd, (char*)&myData, sizeof(myData);
//client side
recv(sockFd, (char*)&myData, sizeof(myData);
printf("large word is %s\n", myData.max_word) ;
printf("small word is %s\n", myData.min_word) ;
printf("total words is %d\n", myData.word_count) ;
Run Code Online (Sandbox Code Playgroud) 我想知道pychm包的一些用法:
我也试图在Windows上安装python chm包以便更好地理解.但是当我执行时,pip install pychm我收到以下错误:
chm/swig_chm.c(681) : fatal error C1083: Cannot open include file: 'chm_lib.h': No such file or directory
Run Code Online (Sandbox Code Playgroud)
有人可以解释我所有这些问题.这可能是一个非常微不足道的查询,但一直困扰我很长一段时间
我是C#的新手.我创建了一个List对象,然后我在特定项目上执行BinarySearch.但搜索结果似乎很奇怪.这是代码:
class Element
{
public int x;
public Element(int val) { x = val; }
}
class MyContainer : IComparable<MyContainer>
{
public Element elem;
public MyContainer(int val) { elem = new Element(val); }
public MyContainer(Element e) { elem = e; }
public int CompareTo(MyContainer obj)
{
if (elem.x < obj.elem.x) { return -1; }
else if (elem.x == obj.elem.x) { return 0; }
else { return 1; }
}
}
class Program
{
static void Main(string[] args)
{
MyContainer container1 …Run Code Online (Sandbox Code Playgroud) 我试图threading在Python中使用该模块。现在我有一个关于该模块支持的线程类型的查询。即这些线程是用户空间线程还是内核空间线程
我正在执行一个java代码,我有一个AtomicInteger1000个线程正在尝试执行的代码incrementAndGet().我期待最终值为1000.但每次运行都会产生各种不同的值.代码如下:
class task implements Runnable {
AtomicInteger i ;
task(AtomicInteger ai) {i =ai ;}
public void run() { i.incrementAndGet() ; }
}
class jlt {
public static void main(String[] args) throws Exception {
AtomicInteger atomicInt = new AtomicInteger(0);
ExecutorService executor = Executors.newFixedThreadPool(2);
for(int i=1; i<=1000; i++)
executor.submit(new task(atomicInt)) ;
executor.shutdown() ;
System.out.println(atomicInt.get()); // 1000 is expected
}
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚我在这里或在我的理解中犯的错误
我有一段代码,作为一些事件处理的一部分,我在word文档中选择一个图像并将其复制到一个文件中.但是在事件处理程序完成后,当我在处理完事件后返回word时,图像显示为选中状态.代码段如下:
foreach (Word.InlineShape shape in shapes)
{
string filepath = "somepath";
shape.Select();
Word.Application application = Globals.ThisAddIn.Application;
application.Selection.CopyAsPicture();
Computer comp = new Computer();
Image image = comp.Clipboard.GetImage();
image.Save(filepath, System.Drawing.Imaging.ImageFormat.Jpeg);
comp.Clipboard.Clear();
}
Run Code Online (Sandbox Code Playgroud)
我希望这个形状不应该显示为选中,因为形状选择只是某些事件处理的一部分.
有没有办法取消选择这种形状.
Thanx为您的建议.
我读到gcc提供了将全局变量定义为寄存器存储变量的支持.我想知道的是标准是否有这种支持的任何规范.
我正在尝试以下代码:
int main() {
int x[10] ;
int a[] = {1,2,3,4,5} ;
int n ;
int b[n] ;
//int c[] ; gives compilation error
cout<<sizeof(x)<<endl ; //prints 40
cout<<sizeof(a)<<endl ; //prints 20
cout<<sizeof(b)<<endl ; //prints 4
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我定义时到底发生了什么b.我试图阅读类似问题的答案,但我没有得到满意的答复.因为数组是静态创建的,所以在声明它们时必须给出大小.那为什么声明b有效.是否sizeof(b)表明这只是作为一个int pointer
在阅读__new__时,我在StackOverflow本身遇到了一个例子.当我正在研究这个例子时,我稍微修改了代码.修改后的代码如下:
class A1(object):
def __new__(cls):
print 'in new'
def __init__(self):
print 'in init'
a = A1()
class A(object):
_dict = dict()
def __new__(cls):
if 'key' in A._dict:
print "EXISTS"
return A._dict['key']
else:
print "NEW"
return super(A, cls).__new__(cls)
def __init__(self):
print "INIT"
A._dict['key'] = self
print ""
a1 = A()
a2 = A()
a3 = A()
Run Code Online (Sandbox Code Playgroud)
输出如下:
in new
NEW
INIT
EXISTS
INIT
EXISTS
INIT
Run Code Online (Sandbox Code Playgroud)
也就是说,当为类'A1'创建实例时,只执行__new__,而对于类'A'实例,正在执行__new__和__init__.
我无法弄清楚原因.
我想创建一个带有数据成员的java类, id这样每个对象都有自己id的对象,但在对象创建期间分配了对象id,之后无法对其进行修改.
我刚刚在 ubuntu 20.04 上将编译器升级到 C++20。g++ version给我以下输出:
c++ (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0\nRun Code Online (Sandbox Code Playgroud)\n我正在按照stackoverflow上的建议尝试以下代码
\nconstexpr int f() {\n std::vector<int> v = {1, 2, 3};\n return v.size();\n}\n\nint main() {\n static_assert(f() == 3);\n}\nRun Code Online (Sandbox Code Playgroud)\n但我收到以下错误:
\nerror: variable \xe2\x80\x98v\xe2\x80\x99 of non-literal type \xe2\x80\x98std::vector<int>\xe2\x80\x99 in \xe2\x80\x98constexpr\xe2\x80\x99 function\nRun Code Online (Sandbox Code Playgroud)\n我是不是哪里出错了。或者是我的安装不正确
\n