假设我有
void func(foo & obj)
Run Code Online (Sandbox Code Playgroud)
我有
foo * object;
Run Code Online (Sandbox Code Playgroud)
我该如何object
论证func
?
string a=NULL;
Run Code Online (Sandbox Code Playgroud)
它给出了错误.为什么以及如何将字符串初始化为NULL?
但是当我写作
string a="foo";
Run Code Online (Sandbox Code Playgroud)
这很好用.
以下代码打印:
5
Run Code Online (Sandbox Code Playgroud)
为什么打印5?如果它返回5为什么它不打印"詹姆斯"?我不明白下面的代码.如果我删除了else字,则打印-1.但是它不应该返回默认值吗?
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int fonk()
{
int a = 5, b = 3;
int c = a*b;
if(c >10)
{
if( a<b && a >0)
{ cout <<"James";
return a;
}
else if(b<0)
{
return b;
}
}
else return -1;
}
int main()
{
int x = fonk();
cout << x;
}
Run Code Online (Sandbox Code Playgroud) 我正在学习运算符重载.当重载"<<"运算符时,正在使用"out"而不是"cout".我不明白为什么.
ostream &operator<<( ostream &out, const IntList &L ) {
out << "[ ";
for (int k=0; k< L.numItems; k++) {
out << L.Items[k] << ' ';
}
out << ']';
}
Run Code Online (Sandbox Code Playgroud)
我想问一下cout和out之间的区别,如果我使用cout而不是out,会发生什么.谢谢你的回答.
下面的代码是类的构造函数,这个类有一个成员
int ** busyhours ;
Run Code Online (Sandbox Code Playgroud)
构造函数
Instructor::Instructor ( int id , string name )
{
this->id = id ;
this->name = name ;
// initialize busyhours
this->busyhours = new int * [DAYS_WORKING] ;
for ( int i = 0 ; i < DAYS_WORKING ; i++ )
{
busyhours[i] = new int[HOURS_PER_DAY] ;
for ( int j = 0 ; j < HOURS_PER_DAY ; j++ )
busyhours[i][j] = 0 ;
}
}
Run Code Online (Sandbox Code Playgroud)
busyhour成员首先与此指针一起使用但是在没有此指针的情况下使用它.我不明白为什么.谢谢你的回答.
#include <iostream>
using namespace std ;
int main()
{
int a=5, b=4;
cout<< a==b;
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能打印这段代码.我该如何打印布尔值?
我读到ADT堆栈可以使用实现
数组
链表
ADT列表
但是当我使用堆栈时,我只是调用堆栈库.这些实现堆栈库中的哪一个使用?