尝试使用一些自定义属性创建元素
function x(){
var f=document.createElement("div");
this.name="monkey";
return f;
}
x.prototype.myFunction=function(){
alert(arguments[0]+this.name);
};
var c=new x();
c.myFunction("hello");
Run Code Online (Sandbox Code Playgroud)
浏览器说c.myFunction不是一个函数
所以我想,以检查是否有人进入:\n
('\'
然后'n'
)从键盘到一个字符串,所以我做这样的事情:
if ( ((str[i] == '\') && (str[i+1] == 'n')) ) {
//...
}
Run Code Online (Sandbox Code Playgroud)
然而,这不起作用,因为它识别\
为转义字符并且整个事情中断.
有更好的方法吗?
考虑以下两个例子
Example A:
foo a;
std::vector<foo> vec;
vec.push_back(a);
vec.clear(); //Destructor of a is called;
Example B:
foo *b = new foo();
std::vector<foo*> vec;
vec.push_back(b);
vec.clear(); //Destructor of b is not called;
Run Code Online (Sandbox Code Playgroud)
我想知道为什么在向量被清除时调用向量中对象的析构函数以及为什么在向量被清除时不调用指针的析构函数.
main(){
int a = 5;
int b = 6;
printf("%d %d %d",a==b,a=b,a<b);
}
Run Code Online (Sandbox Code Playgroud)
在我的测试中输出
1 6 1
在上面的程序中,我期望输出为0 6 0.在一些编译器中,它给出了这个输出(例如Xcode),但在某些其他编译器中,它输出为1 6 1.我找不到解释.这也是序列点的情况.
考虑以下计划
main(){
int a = 5;
int b = 6;
printf("%d %d %d",a<b,a>b,a=b);
printf("%d %d",a<=b,a!=b);
}
Run Code Online (Sandbox Code Playgroud)
在我的测试中输出
0 0 6 1 0
这个下面的程序正在给出正确的输出,我期待的是0 0 6 1 0但是为什么上面的程序在大多数编译器中没有给出输出060
我正在尝试将字符串转换为'LPCTSTR',但是,我得到了以下错误.
错误:
cannot convert from 'const char *' to 'LPCTSTR'
Run Code Online (Sandbox Code Playgroud)
码:
std::string str = "helloworld";
LPCTSTR lp = str.c_str();
Run Code Online (Sandbox Code Playgroud)
还试过:
LPCTSTR lp = (LPCTSTR)str.c_str();
Run Code Online (Sandbox Code Playgroud)
但是,打印垃圾值.
我在范围内进行了变量b(范围外的声明)的类型转换,并为b赋予了新的val,当范围结束时,b的val似乎是错误的。
这是在我的Macbook上发生的,它的gcc版本是gcc-8(Homebrew GCC 8.3.0)8.3.0。我在gcc版本为5.4.0的linux笔记本电脑上尝试了相同的代码,并且代码运行良好。
std::vector<int> a = {1,2,3,4};
int b;
{
size_t i = 0, b = a[i];
//this time type of b is size_t
++i;
b = a[i];
}
std::cout << "b = " << b << std::endl;
Run Code Online (Sandbox Code Playgroud)
在我的Mac上,结果是b = 0
在Ubuntu 16上,结果是b = 1
类型转换的两个版本的gcc有什么区别?
还是一个错误?
如果我想要一个while循环:虽然变量不等于几个不同的值,这是否有效?:
while (uInput != ('a' || 'b' || 'c')){
//do something to make it equal one of those
}
Run Code Online (Sandbox Code Playgroud)
或者我是否必须单独将uInput与a,uInput与b进行比较,依此类推?
所以我有一个问题...我正在建立一个网站,我遇到了一个问题.我以1920*1080p的分辨率制作了我的网站,当我改变到不同大小时,所有元素都被移动了.我想做的就是让所有元素都不被移动一切都是我想要的,如果你在手机上不仅需要向上和向上滚动而是向左和向右滚动,我会发布我的代码.
我目前正在自学C和C++.
我找不到类似的问题,但我想要一些关于C和C++设计实践的好解释.
return()
吗?为了显示:
bool A (blah, blah)
{
bool a = false;
a = B(); // B returns bool type
return a;
// OR
return (B());
}
Run Code Online (Sandbox Code Playgroud)
c++ ×5
c ×3
html ×3
c++11 ×2
css ×1
javascript ×1
loops ×1
return ×1
shadowing ×1
syntax ×1
tchar ×1
vector ×1
while-loop ×1
widestring ×1
windows ×1