由买买提看人间百态

topics

全部话题 - 话题: couted
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
s*********y
发帖数: 615
1
来自主题: JobHunting版 - 发两个软件组的面试题
在会议室里看到上个礼拜面试新毕业生的东西,,发两个出来,估计可能对大家也没啥
实际作用,反正等着开会也没啥事干,,就当给自己以后找工作攒个人品了。。呵呵,
,我不会软件组的,所以也不知道难易,也没答案
behavioral:
What is the hardest software problem that you have debugged. how did you go
about doing it? what caused the bug
XML Parser(我们的东西会用到xml。所以)
XML exists to define tests available on some system:




Design and implement a class to:
1.store and manage... 阅读全帖
S******t
发帖数: 151
2
来自主题: JobHunting版 - 问两道fb题
我贴一个第一题能通过的代码吧:
vector bestA;
int bestLen;
void search(int idx, int sum, int len, vector>>& f,
vector& ret, vector& A) {
//cout << idx << " " << sum << " " << len << endl;
if (idx == 0) {
int lenA = bestA.size();
vector v = ret;
/*
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
*/
if (v.size() < lenA || lenA == 0) {
bestA = v;
return;
... 阅读全帖

发帖数: 1
3
是不是真的“你的感想”,我确实有问号的,我记得你写过一个C++的codes,不过这个
code暴露了一个问题, 就是你都不知道C++的package都是独立写的,根本不用cout这
种语句(如下),是用user defined package里专用的不同level的 print function.
你大概是看着学计算机好找工作,所以初略学了一点皮毛而已。 理科生会不懂C++吗?
那还怎么吃饭?
发信人: reknaz (拖把套), 信区: Joke
标 题: Re: 我帖子又被蹊跷删除了,等钻风答复吧
发信站: BBS 未名空间站 (Wed Jul 6 10:31:45 2016, 美东)
哈哈
cout<<"我发的我的帖给删了";
for (int i=0;i<100;++i) cout<<"的贴也给删了";
cout<
希格斯机制大概是这样。除非质量项和真空极化振幅的一个极值有关系,否则规范玻色
子获得不了质量。在二唯时空,这个极值可以由一个费米子对产生。但在四维情况下,
这个真空极化振幅的极值只能由一个标量粒子产生,而这种粒子在对称性不破缺的情况
下是不存在的。... 阅读全帖
r****z
发帖数: 12020
4
for (int i=0;i<127;++i) cout<<"创造";
cout<<"高度精密的宇宙";
for (int j=0;j<127;++j) cout<<"的 The Intelligent ";
cout<<"是谁创造的?"< 看本版传教帖深受启发深受启发。。。
b*****l
发帖数: 9499
5
来自主题: Thoughts版 - OpenMP 求救。。。
在学 OpenMP,第一步就不通:设多线程失败。。。
TestOMP.cpp 的 code 很简单:开 5 个线程,每个介绍一下自己,就完事了.
#include
#include
using namespace std;
main () {
omp_set_num_threads(5);
cout << "Fork! " << endl;
#pragma omp parallel
{
// Obtain and print thread id
cout<< "Hello World from thread = " << omp_get_thread_num()
<< " of " << omp_get_num_threads() << endl;
// Only master thread does this
if (omp_get_thread_num() == 0)
cout << "Master thread: number of threads = " <<
omp... 阅读全帖
Y********6
发帖数: 28
6
刚开始学,第三堂课就遇到困难。。。实在弄不出来。。。
题目是这样的
* Write a program that reads from a file called input.txt until the file
contains the word end.
* For each word you encounter, you will determine if the word is
alphabetically before or after the previous encountered word.
* For a word that is alphabetically after the previous word, write the word
to the screen and then say AFTER. For words that are before the previous,
write the word BEFORE. For the first word, write COMES FIRST. For words that
are the same, wr... 阅读全帖
l********a
发帖数: 1154
7
又来一次
#include
#include
#include
using namespace std;
int main()
{
ifstream fin("test.txt");
string curWord, lastWord = "";
fin >> curWord;
while (curWord.compare("end")!=0)
{
if (lastWord.empty())
{
cout << curWord << " COMES FIRST" << endl;
}
else if (curWord>lastWord)
{
cout << curWord << " AFTER " << lastWord << endl;
}
else if (curWord {
... 阅读全帖
b*****l
发帖数: 9499
8
来自主题: Linux版 - OpenMP 求救。。。 (转载)
【 以下文字转载自 Thoughts 讨论区 】
发信人: bigsail (河马·旋木), 信区: Thoughts
标 题: OpenMP 求救。。。
发信站: BBS 未名空间站 (Sat Apr 30 02:18:47 2011, 美东)
在学 OpenMP,第一步就不通:设多线程失败。。。
TestOMP.cpp 的 code 很简单:开 5 个线程,每个介绍一下自己,就完事了.
#include
#include
using namespace std;
main () {
omp_set_num_threads(5);
cout << "Fork! " << endl;
#pragma omp parallel
{
// Obtain and print thread id
cout<< "Hello World from thread = " << omp_get_thread_num()
<< " of " << omp_get_num_threads() << endl;
... 阅读全帖
e******r
发帖数: 220
9
来自主题: Programming版 - ask a C++ inheritance question

那要不要在FooToo 和Bar定义的时候也加上virtual, 换句话说, 下面的是不是
每个inherutance都要加上virtual? 我试了一下, 好象virtual inheritance的个数决定下面的例子的结果.

#include
class Foo
{
public:
Foo(){std::cout<<"Foo";}
};
class Bar: Foo
{
public:
Bar(){std::cout<<"Bar";}
};
class FooToo:virtual Foo
{
public:
FooToo(){std::cout<<"FooToo";}
};
class FooTooBar:virtual FooToo, virtual Bar{
public:
FooTooBar(){std::cout<<"FooTooBar";}
};
int main()
{
FooTooBar a;
return 0;
}
j*******a
发帖数: 101
10
来自主题: Programming版 - reverse words, not the Microsoft one!!!
i wrote one. it works well.
#include
using namespace std;
char* reverse_word (char* str);
int main(int argc, char** argv){
char str[] = "this is very beautiful ";
cout <<"["< cout << "["<< reverse_word(str)<<"]"< char str2[] = "jokeslala rejected some 100k offers ";
cout <<"["< cout << "["<< reverse_word(str2)<<"]"<
system("pause");
return 0;
}
char* reverse_word (char* str){
if (str =
n*******s
发帖数: 482
11
恩 仔细看了一下,是我的测试代码写错了。
String s(" hello world ");
cout< const char* o = (const char*)s;
cout<<"const char* o="< char* o1 = (char*)o;
cout<<"char* o1="< remove_blanks(o1);
cout<<"remove_blanks(const char* -> char*)o1="< 结果没啥问题。
我想对于这种Const char* --> char*的转换,如果后面对char*的操作是变短 就没
啥问题,如果变长 可能会覆盖其他变量吧。
谢谢observer RP++
:)
m******t
发帖数: 4077
12
来自主题: Programming版 - 问个简单的memory allocation 的问题。
1, 以下小程序里没有给b allocate space, 为什么编译器不报错呢?g++
2, a[5]到底在内存里面占几个字节?是5个吗?但是最后一个已经给了 '\0', 对吗?
3, a[5]是在stack中还是在heap中啊?如果用new 给b分配地址的话是在heap中,对吧?
#include
using namespace std;
int main()
{
char * b;
char a[5] = "1234";
strcpy(b, a);
cout << a < cout << b << endl;
cout << "size of b " << sizeof(b)< cout << "size of a " << sizeof(a)< return 0;
}
d*******d
发帖数: 2050
13
来自主题: Programming版 - 来,出个题
非常非常简单。
先自己写下结果,然后运行试试。
void f(char a[]){
cout << sizeof(a) << endl;
cout << sizeof(*a) << endl;
}
main(){
char a[10];
cout << sizeof(a) << endl;
cout << sizeof(*a) << endl;
f(a);
}
z******i
发帖数: 59
14
来自主题: Programming版 - 请教 C++的一个困惑 (operator delete)
You don't define "delete" operator be virtual. You make destructor virtual.
See below.
#include
#include
using namespace std;
class A
{
public:
virtual ~A()
{
cout << "I am A\n";
}
//void operator delete(void* p, size_t size){cout << size << endl;};
private:
int k;
};
class B:public A
{
public:
virtual ~B()
{
cout << "I am B\n";
}
//void operator delete(void* p, size_t size){cout << size<
s***e
发帖数: 122
15
来自主题: Programming版 - 关于c++的constructor的面试题
现在明白了,呵呵,怎么说来着,it's more than clear now.
主要是我们如果用顺序的方式去解释,就没法反映其中的层次。而把compiler生成的整个函数体写出来之后,就清晰多了。
刚才很有兴趣的用Java也测试了一下,发现结果是一样的。不过把virtual函数放到constructor之后就有不同的效果了。
C++输出是:
a
a.f()
c
b
Java输出是:
a
b.f()
c
b
// =========== C++ Implementation ===========
#include
#include
using namespace std;
class a{
public:
a(){cout<<"a"< virtual f() {cout<<"a.f()"< };
class c{
public:
c(){cout<<"c"< };
class b: public a {
public:
b(){cout<<"b"< virtual f() {c
m*******o
发帖数: 264
16
来自主题: Programming版 - 编译错误问题
#include
#include
#include
using namespace std;
class Phones{
public:
Phones(){cout << "Phone object created!" << endl;} //Create and and
initialize phone object
virtual void isDialing() { cout << "base virtual " << endl;}
virtual ~Phones(){ cout << "~Phone" << endl; } //Destroy the Phone
object
protected:
string PhoneNumber;
string ModelType;
};
class LandlinePhone: public Phones{
public:
LandlinePhone(){cout << "LandlinePhone" << endl;}
voi
b***y
发帖数: 2799
17
来自主题: Programming版 - [合集] 为什么10进制输出是负的?
☆─────────────────────────────────────☆
grasssu (没有昵称) 于 (Thu Nov 13 01:27:05 2008) 提到:
VC 8编译下列程序
//求文件大小
ifstream is( "Cars.mkv" );
is.seekg (0, ios::end);
streampos length = is.tellg();
//assert ( length > 0 ); //failed
cout.flags(ios::hex);
cout << length << endl; //输出正的 89c01076, 这个数字换成十进制是
2311065718是正确的。
cout.flags(ios::dec);
cout << length << endl; //输出-1983901578
为什么10进制就是负数呢?我怎么才能得到正确结果?
在ubuntu上面得到结果就是正确的。VC8为什么这么奇怪?
☆─────────────────────────────────────☆
redroof (yellow
w********p
发帖数: 948
18
#include
using namespace std;
class Base
{
public:
Base(){ cout<<"Constructor: Base"< ~Base(){ cout<<"Destructor : Base"< };
class Derived: public Base
{
//Doing a lot of jobs by extending the functionality
public:
Derived(){ cout<<"Constructor: Derived"< ~Derived(){ cout<<"Destructor : Derived"< };
int main()
{
Derived *Var = new Derived();

Base Var2;
Var2 = (Base) *Var;
delete Var;
return 0;
}
output:
Constructor: Base //1
Co
i********r
发帖数: 131
19
来自主题: Programming版 - C++怎么写任意重重循环?
thinking in c++11 and a more general solution:
#include
#include
using namespace std;
void do_something(const vector& vars)
{
cout << "do_something with loop variables: ";
for (auto& i: vars)
cout << i << " ";
cout << endl;
}
void myLoop(vector& vars)
{
do_something(vars);
}
template
void myLoop(vector& vars, unsigned int n, Args... args)
{
auto index = vars.size();
vars.push_back(0);
... 阅读全帖
i********r
发帖数: 131
20
来自主题: Programming版 - C++怎么写任意重重循环?
If the number of loops are only known at run time, the variadic template won
't work. The only way I can think of is recursion:
#include
#include
using namespace std;
void do_something(const vector& vars)
{
cout << "do_something with loop variables: ";
for (auto& i: vars)
cout << i << " ";
cout << endl;
}
// method 2:
void myLoop(const vector& inputs, vector& vars)
{
if (inputs.size() == vars.size()) {
... 阅读全帖
z****e
发帖数: 2024
21
来自主题: Programming版 - 再问C++初始化问题。
为了验证我的一些想法,我写了如下代码,
标号2,4的运行区别不是很理解。
class X{
public:
int i;
};
X* px=new X;
X gox;
int main(){
X* lpx=new X;
std::cout<i< std::cout<i< X ox;
std::cout< std::cout< }
结果:
0
0
0
-1077381160
主要是2,和4,为什么2和4有区别呢?
stack和heap上,初始化还不一样?
stack和静态区不一样是可以理解的。
另外
X* lpx=new X;

X* lpx=new X();
貌似没有区别,实际有没有区别呢?
因为heap上要zero out,所以heap的效率要轻微的低于stack???
p*u
发帖数: 2454
22
来自主题: Programming版 - how do I reseat a reference?
I know a reference in C++ cannot be reseated; am just trying to test
this concept. But it seems to me that as long as u wish to implement an
assignment operator u will not get a "reference reseating" compiler
error, it will just copy value of second object to first object. How can
I have a true compiler error?
Sample code:
"
#include
#include
int main()
{
std::vector v1( 10, 1 );
std::vector v2( 20, 2 );
std::vector& ref = v1;
for( int i = 0; i < re... 阅读全帖
s*******o
发帖数: 392
23
本人仍在继续学习cplusplus。com网站的教程,
看到了static member这一章节,
这是例子code
#include
using namespace std;
class CDummy
{
public:
static int n;
CDummy(){ n++ ;};
~CDummy(){ n--; };
};
int CDummy::n = 0;
int main()
{
CDummy a;
CDummy b[5];
CDummy*c = new CDummy;
cout << b[2].n < cout << c->n < delete c;
cout << CDummy::n < cout << b->n <
system("PAUSE");
return 0;
}
我的问题是问什么在delete c之前n输出值为7, 而在delete c之后的输出值时6?大家
能不能
试一试?而且... 阅读全帖
a****m
发帖数: 693
24
#include
#include
#include
using namespace std;
// this function removes trailing spaces from x
void trim (char *str, int size )
{
int i;

/* remove the null terminator */
for ( i = size; i >0; i=i-1 )
{
if ( str[i] == '\n' || str[i]=='\t' || str[i]==' ' )
{
str[i-1] = '\0';
/* we're done, so just exit the function by returning */
return;
}
}
/* if we get all the way to her... 阅读全帖
r*******y
发帖数: 1081
25
来自主题: Programming版 - post increment
I use g++ compiler. Something strange here.
case 1:
int a[3]={1, 10, 100};
int *p = a;
cout << *p++ << endl << *p < The out put is 1 1
I can not understand this. It is supposed to be 1 10, right?
case 2:
if I write it as
cout << *p++ < cout << *p < the output is 1 10 as it is supposed to be.
case 3:
Also if I have this code
int i = 1;
cout << i++ < The output is also as supposed to be, that is 1 2;
So here case 2 and case 3 are well understood. What is wrong w... 阅读全帖
a***y
发帖数: 2803
26
#include
using namespace std;
int main() {
int a[5];
a[0]=9;
a[1]=8;
a[2]=7;
a[3]=6;
a[4]='\0';
int i=1;
a[i++]=i;
a[i]=i++;
(a[3]=4)=5;
cout << "a[0] is "<< a[0] << endl;
cout << "a[1] is "<< a[1] << endl;
cout << "a[2] is "<< a[2] << endl;
cout << "a[3] is "<< a[3] << endl;
return 0;
}
结果是
a[0] is 9
a[1] is 1
a[2] is 2
a[3] is 5
(a[3]=4)=5;最后a[3]等于5,不是4. 语法正确,结果正确.

say
operators:
precedenc
kick
ta
A**u
发帖数: 2458
27
来自主题: Programming版 - 请教c++ non-vitura interface
你是对的
class B{
public:
~B();
void run(){do();}
private:
void do(){cout << "B"};
}
class D:public B{
private:
void do(){cout << "D"}
}
B* p = new D;
p->run() 显示 B.
class B{
public:
~B();
void run(){do();}
private:
virtual void do(){cout << "B"};
}
class D:public B{
private:
virtual void do(){cout << "D"}
}
B*p = new D;
p->run() 显示 D
t****t
发帖数: 6806
28
来自主题: Programming版 - What does the default constructor do?
我来给你看看真正的例子是怎么写的, 那个街头程序员明显什么都没搞清楚就在那里写
blog.
new, new什么? 有没有括号? 这都是不一样的.
当然C++在这个事情上是不intuitive, 也难怪大家抱怨.
#include
#include
using namespace std;
struct A {
int c[10];
};
struct B {
B() {};
int c[10];
};
int main()
{
/* fill the memory with garbage and release,
* just to show the difference */
int *g=new int[10000];
for (int i=0; i<10000; i++) g[i]=rand();
delete g;
A* a1=new A;
A* a2=new A();
B* b1=new B;
B* b2=new B();
c... 阅读全帖
f***t
发帖数: 25
29
来自主题: Programming版 - 一个诡异的const_cast问题
对于简单类型的const_cast,下面代码:
int const i=2; //现在i值const了
int* k = const_cast(&i); //用引用也行,结果是一样的
*k=3; //借被const cast 的k改i值;成功;
cout< cout<<*k< cout<<&i< cout< 以上是VC6的编译。
把简单类型换成类就不会有这种现象,这是不是VC6的一个bug?
L*******r
发帖数: 310
30
来自主题: Programming版 - C++的一个小疑问,求解惑
代码如下:
class IntVector
{
.......
....
..
void IntVector::copy(const IntVector & orign)
{
vsize=orign.size();
vcapacity=orign.capacity();
data= new int [vcapacity];
for(unsigned i=0;i {
cout << "orign: " << orign.data[i] << endl;
data[i] = orign.data[i];
cout << "data[i]: " << data[i] << endl;
}
}
}
int main()
{
IntVector v1;
v1.print();
v1.push_back(1);
v1.print();
v1.push_back(2);
v1.print();
... 阅读全帖
r**a
发帖数: 536
31
来自主题: Programming版 - 菜鸟请教smart pointer
下面的code中,输出为"Constructor, Constructor, Destructor, 3" 前两个
constructors分别是create b1 and b2是出现的。第3个Destructor应该是对应到“b1
= b2;"。我的问题是此时b2已经被free掉了,为啥最后的结果是3呢?哪位大牛给解释
解释。谢谢了。
#include
#include
#include
#include
class StrBlob
{
public:
typedef std::vector::size_type size_type;
StrBlob();
StrBlob(std::vector &il);
size_type size() const { return data->size(); }
bool empty() const { return data->empty(); }
void push_... 阅读全帖
H****n
发帖数: 26
32
如题,请大师们帮帮忙,编译器现在主要报错在静态变量打初始化部分,我百思不得其
姐。
#include
using namespace std;
class link{
private:
string ss;
link *prev;
link *next;
static int count; //the counter to show how many nodes
int pos; //the position to insert node
static link* fp; //a temp node for insertion
static link* head;
static link* tail;
public:
link(string s1="", int i=0):ss(s1),pos(i){
if(head==NULL&&tail==NULL){
... 阅读全帖
t****t
发帖数: 6806
33
来自主题: Programming版 - 为什么大家都说c++水很深?
楼上的兄弟拿一些名词出来吓唬人你可以说他不对, 但是你要说他说的几个事情"有屁
用处", 那我只能说你无知者无畏了.
我前面说了, 最简单的C++ hello world里就依赖ADL, 只是初学者没注意到而已. 说实
话不是什么高深的概念.
std::cout<<"Hello world\n";
事实上等于
operator<<(std::cout, "Hello world\n");
但是operator<<是在std::里面的, 为什么不写std::operator<<(std::cout, "Hello
world\n");? 因为参数std::cout在std::里, 所以编译器找不到operator<<(..., ...)
的时候就会去找std::operator<<. 说穿了了是很简单的一件事情, 但是没有它还不行;
有了它, 又有名污染的问题.
另外ABI的问题, 写多的人都知道是很头痛的一件事情.
提ADL和ABI这些事情, 我想devilphoenix不是想说C++很高深, 而是说C++遇到的麻烦和
陷阱远远不止什么内存分配这类的小事情. 你非要说人显摆当然我也没办... 阅读全帖
t****t
发帖数: 6806
34
来自主题: Programming版 - 为什么大家都说c++水很深?
楼上的兄弟拿一些名词出来吓唬人你可以说他不对, 但是你要说他说的几个事情"有屁
用处", 那我只能说你无知者无畏了.
我前面说了, 最简单的C++ hello world里就依赖ADL, 只是初学者没注意到而已. 说实
话不是什么高深的概念.
std::cout<<"Hello world\n";
事实上等于
operator<<(std::cout, "Hello world\n");
但是operator<<是在std::里面的, 为什么不写std::operator<<(std::cout, "Hello
world\n");? 因为参数std::cout在std::里, 所以编译器找不到operator<<(..., ...)
的时候就会去找std::operator<<. 说穿了了是很简单的一件事情, 但是没有它还不行;
有了它, 又有名污染的问题.
另外ABI的问题, 写多的人都知道是很头痛的一件事情.
提ADL和ABI这些事情, 我想devilphoenix不是想说C++很高深, 而是说C++遇到的麻烦和
陷阱远远不止什么内存分配这类的小事情. 你非要说人显摆当然我也没办... 阅读全帖
s*w
发帖数: 729
35
改了两个小时,终于改好了一半
现在一个 producer 一个 consumer 没问题了;上个版本的 consumer 没循环,只能处
理一行;而且在睡觉的时候没有  guard spurious wakeup, 我以为用 if可以算
guard 了,其实需要 while loop来guard 或者用 data2consume.wait(lck,!data.
empty())
糟糕的是 多 consumer 还是不行,会 deadlock 。
再次呼唤高人指点一下
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int MAXCAPACITY = 3;
mutex mx;
deque data;
map freq;
c... 阅读全帖
t**r
发帖数: 3428
36
try this,
you will understand
1 using namespace std;
2 #include
3 #include
4
5 int main(){
6 int *a,*b;
7 cout<<&a<<" "<<&b< 8 cout< 9 a=b;
10 cout<<&a<<" "<<&b< 11 cout< 12 return 0;
13 }
m*********a
发帖数: 3299
37
来自主题: Programming版 - c++ copy reference 还是deep copy
vector v;// a v vector
{
Entity e;//init an entity object on stack and set health to 100
Entity *ptr=&e; //point ptr to e
v.push_back(ptr);//copy the reference(?) ptr to vector v
cout<<"In the block"< cout<getHealth()< }//e is destroyed and e out of range
cout<<"Out of the block"< cout<getHealth()< // print out 100, is the object point... 阅读全帖
D***n
发帖数: 6804
38
你需要知道编译器是怎么玩的,两段程序在编译器,前半部份基本相同,实际上是:
char i = 'x';
char cp = &i;
char *p;
p = cp;
*p = y; /* i 的内容已经被改成 'y'了 */
不同的地方, 第一段:
cout << *p < cout << *cp << endl;
count << 'x' << endl; 这里编译器直接把常量'x'放这里。
第二段:
cout << *p < cout << *cp << endl;
count << i << endl; 这里编译器读取的是变量i的内容;
D***n
发帖数: 6804
39
你可以看看这个打出来什么:
const char i='x';
const char *cp=&i;
char *p;
p=const_cast(cp);
*p='y';
std::cout<<*p< std::cout<<*cp< std::cout< const char *t = &i;
std::cout<<*t< 我这里的结果是 y y x y
C*****n
发帖数: 1049
40
来自主题: Programming版 - 出道面试题
这道题我在snapchat onsite的时候也遇到了,以前没见过,当时只给出了dfs的解。
现在给出dfs和dp的解,可能有bug,没做深度测试。
#include
#include
using namespace std;
//basically we can use a dfs to solve the problem
bool jumpDfs(vector & stone_pos, int pos, int speed) {
int n=stone_pos.size();
if(pos==n-1) return true;
if(!stone_pos[pos] || pos>=n || speed<1) return false;
for(int s=speed-1; s<=speed+1; ++s) {
if(jumpDfs(stone_pos,pos+s,s)) return true;
}
return false;
}
//assume init_spee... 阅读全帖
c***s
发帖数: 15
41
来自主题: Programming版 - 请教一个C++的设计问题
//样本代码如下,把具体decoder方法在不同type上实现就行
#include
enum decoder_type
{
type_A = 0,
type_B = 1,
type_C = 2,
no_decoder_available = 3
};
template
class decoder_algorithm
{
};
template<>
struct decoder_algorithm
{
static bool is_compatible () { return false; }
static void decode() { std::cout << "decoder A" << std::endl; }
};
template<>
struct decoder_algorithm
{
static bool is_compatible () { return false; }
static void decode() { std::cout << "decoder B" ... 阅读全帖
y**b
发帖数: 10166
42
来自主题: Programming版 - C++含有指针成员的类
这个自然,就是不明白编译器怎么判断ptr1还在vector里面呢,总之reset有点特别,
或者智能指针实现有点特别。
如果是个内置指针,放入容器,然后delete该指针,会调用destructor,这个与上面的
行为不一样。代码如下:
int main(int argc, char** argv)
{
A *ptr1 =new A();
A *ptr2 = new A();
std::vector ptrList;
{
std::cout << "In the nested scope 1n";
ptrList.push_back(ptr1);
ptrList.push_back(ptr2);
}
{
std::cout << "In the nested scope 2n";
delete ptr1;
delete ptr2;
}
{
std::cout << "In the nested scope 3n";
ptrList.c...
阅读全帖
Y********6
发帖数: 28
43
来自主题: Computation版 - 20个包子,求解c++基础问题 (转载)
【 以下文字转载自 CS 讨论区 】
发信人: Yolanda886 (Yolanda886), 信区: CS
标 题: 20个包子,求解c++基础问题
发信站: BBS 未名空间站 (Sun Feb 3 10:06:51 2013, 美东)
刚开始学,第三堂课就遇到困难。。。实在弄不出来。。。
题目是这样的
* Write a program that reads from a file called input.txt until the file
contains the word end.
* For each word you encounter, you will determine if the word is
alphabetically before or after the previous encountered word.
* For a word that is alphabetically after the previous word, write the word
to the screen and then say AFTER. For words... 阅读全帖
l********a
发帖数: 1154
44
来自主题: Computation版 - 20个包子,求解c++基础问题 (转载)
是c++不是c吧,那用string吧,别用char了
#include
#include
#include
using namespace std;
int main()
{
ifstream fin("test.txt");
string curWord, lastWord = "";
fin >> curWord;
while (curWord.compare("end")!=0)
{
if (lastWord.empty())
{
cout << curWord << " COMES FIRST" << endl;
}
else if (curWord>lastWord)
{
cout << curWord << " AFTER " << lastWord << endl;
}
else if (curWord阅读全帖
d*********1
发帖数: 25
45
来自主题: Quant版 - C++ 问题
为什么下面sstr 重新设置了,打印的还是11 22 呢,而不是55 66?
#include
#include
using namespace std;
int main()
{
istringstream sstr;
sstr.str("11 22");
cout< int i , j;
sstr>>i>>j;
cout<<"i="<
sstr>>i>>j;
cout<<"i="<
l*********o
发帖数: 3091
46
来自主题: DataSciences版 - Data scientist--Zillow电面
#include
#include
#include
#include
using namespace std;
class Element
{
public:
int time;
int count;
Element(int t, int c)
{
time = t;
count = c;
}
};
class IPRecord
{
public:
queue q;
int total_attack;
void add_to_queue(int t, int c)
{
Element ele = Element(t, c);
q.push(ele);
total_attack += c;
}
void normalize_queue()
{
while (q.back().time - q.front().time... 阅读全帖
O******5
发帖数: 483
47
来自主题: Military版 - 一日一个C++(171108)!
#include
int main(int argc, char * argv[]){
double xiaxianyue;
double hairi;
std::cout << "xiaxianyue:";
std::cin >> xiaxianyue;
std::cout << "hairi:";
std::cin >> hairi;
double dsb = xiaxianyue + hairi;
std::cout << dsb << "\n";
return 0;
}

发帖数: 1
48
来自主题: Military版 - 一日一个C++ (5)!
for(int times = 1; times <= sex; ++times) {
int r = fork(); //fuck()
if(!r) {
cout << "my parents fucked and got men";
exit(0);
} else if(r > 0) {
cout << "oh, orgasm!n";
wait(r);
} else
cout << "used anal";
w********p
发帖数: 948
49
【 以下文字转载自 Programming 讨论区 】
发信人: whitetulip (白色郁丁香), 信区: Programming
标 题: 问关于C++Destructor的问题
关键字: 'base class' 'destructor' 'case' 'assignment'
发信站: BBS 未名空间站 (Sat Nov 7 01:06:59 2009, 美东)
#include
using namespace std;
class Base
{
public:
Base(){ cout<<"Constructor: Base"< ~Base(){ cout<<"Destructor : Base"< };
class Derived: public Base
{
//Doing a lot of jobs by extending the functionality
public:
Derived(){ cout<<"Constructor: Derived"< ~Derived()
l*******g
发帖数: 4894
50
来自主题: JobHunting版 - 发个题目给大家复习一下marco
#define sqrt(x) x*x
int main(){
int i=4;
std::cout< std::cout< std::cout< }
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)