我只是学习用C编写代码,我不知道是否有人可以指出我正确的方向,或者给我一个简单的HTTP Get请求的例子.
谢谢 :)
请考虑以下因素:p1 = 1; P2 = 5; P3 = 7; 最高= MAX(P1,P2,P3).
max函数将返回7.我正在寻找创建一个类似的函数,它将返回"p3".我为上面的例子创建了一个小函数(通过简单的比较),如下所示.但是当争论的数量增加时,我遇到了麻烦.
def highest(p1,p2,p3):
if (p1>p2) and (p1>p3):
return "p1"
if (p2>p1) and (p2>p3):
return "p2"
if (p3>p1) and (p3>p1):
return "p3"
有没有更简单的方法来做到这一点>
我试图让这个程序获取用户输入并将其放入公共函数并将其分配给privateVariable,然后我希望它将privateVariable的值返回到main()并将其输出到屏幕,但它显示的全部是未定义的int(-858993460)的值.我在这里有什么合乎逻辑的问题?
#include <iostream>
#include <string>
using namespace std;
class MyClass
{
private:
int privateVariable;
public:
int userVariable;
void setVariable(int userVariable)
{
privateVariable = userVariable;
}
int getVariable()
{
return privateVariable;
}
};
int main()
{
int userVariable;
cin >> userVariable;
MyClass object1;
MyClass object2;
object1.setVariable(userVariable);
object2.getVariable();
cout << object2.getVariable();
system("PAUSE");
return 0;
}
Run Code Online (Sandbox Code Playgroud) 所以我想知道是否有可能有一个具有布尔值的自定义类.
在您的主程序中,您可以:
if(CustomClassVariable){
}
Run Code Online (Sandbox Code Playgroud)
像布尔类一样?
我对vagrant destroy命令感到困惑.
输出vagrant status是
Current machine states:
default running (virtualbox)
Run Code Online (Sandbox Code Playgroud)
但我有两个虚拟框在虚拟框中运行
MacBook-Pro:server john$ vboxmanage list runningvms
"john-servers_default_1415665580149_91312" {114ad904-8629-4c4a-9344-d685c78a8228}
"test" {a6be5689-0ac3-4ac7-845d-97f2f4022cd9}
Run Code Online (Sandbox Code Playgroud)
现在,当我这样做时vagrant destroy,它说你想做什么destroy deafult VM
现在我不确定它会破坏哪台机器.我在testVM 里面,但我不想承担风险.
我试过这个vagrant destroy test,vagrant destroy a6be5689-0ac3-4ac7-845d-97f2f4022cd9但是没有用
删除VM的安全方法是什么?
我在函数参数中使用pass引用传递给const字符串,如下所示:
class Super
{
void alignment(const string & str);
};
void Super::alignment(const string & str)
{
//do some stuff
}
Run Code Online (Sandbox Code Playgroud)
现在如果我使用如下,它会得到相同的结果:
void Super::alignment(string const & str)
{
//do some stuff
}
Run Code Online (Sandbox Code Playgroud)
这两种c ++定义有什么区别?
我对iPhone/iPad编程很陌生.我有for循环的问题,就像我在这个例子中使用的那样.该程序按预期工作.只有在每次调用函数之后(在这个例子中 - (void)writeLabels),它变得越来越慢.谁能告诉我为什么?在此示例中,需要50到100次点击才能发现延迟.但是,一旦我将更多指令打包到循环中,程序就变得太慢,因此只有在点击几下后才能使用.自动释放池也无济于事.
- (void) writeLabels {
label_y = 0;
for (i = 0; i < 23; i++) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(i * i, label_y, 39, 39)];
label.textColor = [UIColor whiteColor];
if (offset == i) {
label.backgroundColor = [UIColor blackColor];
}
else label.backgroundColor = [UIColor blueColor];
[label setText:[NSString stringWithFormat:@"%d", i]];
[self.view addSubview:label];
[label release];
label_y += 40;
}
}
- (IBAction) pushPlus {
++offset;
if (offset == 23) offset = 0;
[self writeLabels];
}
Run Code Online (Sandbox Code Playgroud) 这是关于删除堆上分配的对象的指针.程序如下,
class Sample{
private:
int m_value1;
int m_value2;
public:
Sample();
void setValues(int m_value1, int m_value2);
void display();
};
Sample::Sample(){
this->m_value1 = 0;
this->m_value2 = 0;
}
void Sample::setValues(int m_value1, int m_value2){
this->m_value1= m_value1;
this->m_value2 = m_value2;
display();
if(this != NULL)
{
cout <<"Deleting this pointer!"<<endl;
delete this;
cout <<"this->m_value1 is "<<this->m_value1<<endl;
cout <<"this->m_value2 is "<<this->m_value2<<endl;
}
}
void Sample::display(){
cout <<"Values are "<<this->m_value1<<" and "<<this->m_value2<<endl;
}
int main(){
Sample *obj1 = new Sample();;
obj1->setValues(4,6);
obj1->display();
getch();
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
Values are …Run Code Online (Sandbox Code Playgroud) 来自初级C级程序员的问题:
if (exp)
doX;
else
doY;
Run Code Online (Sandbox Code Playgroud)
分号是语句分隔符,然后我很困惑,如果.. else或嵌套if .. else被称为单个语句?