由买买提看人间百态

topics

全部话题 - 话题: std
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
w********s
发帖数: 1570
1
来自主题: JobHunting版 - fb国内申请的曲折经历+电面
easy job
#include
#include
#include


#include


... 阅读全帖
w********s
发帖数: 1570
2
来自主题: JobHunting版 - fb国内申请的曲折经历+电面
easy job
#include
#include
#include


#include


... 阅读全帖
r*g
发帖数: 186
3

yes you are right,
I tried your idea and it's much faster than before.
int calcHash(std::vector &v)
{
int res = 0;
for(auto ele: v){
res = res * 2 + ele;
}
return res;
}
bool canIWin(int, int sum, std::vector &v, int obj,
std::unordered_map &cache)
{
int key = calcHash(v);
if(cache.find(key) != cache.end()){
return cache[key];
}
... 阅读全帖
b*********d
发帖数: 3539
4
来自主题: WaterWorld版 - 不嫁美国男人的五大理由
STD!STD!STD!STD!STD!STD!STD!
就算婚检阴性,也难保婚不后给诸位国女带来一堆脏病,注意白女都是吃药不带套的。
就国女那个小身子骨,肯定喂不饱十几岁就开荤,天天炮火不断的白男——嫁给没女人
鸟的白loser的除外。隔三差五在外面偷点病毒细菌回来,有外f好受的。
G*****n
发帖数: 3863
5
http://www.bu.edu/phpbin/news-cms/news/?de...92&id=52827
这是波士顿大学的官方链接。
http://www.bu.edu/ssw/about/facultystaff/faculty/hahm/
这是那个发表文章的发考题的链接。
原始数据没找到,因为不知道是哪一篇里面有。不过波士顿大学的网站提到她在演讲中
有原话:
‘Over the course the study, Hahm unmasked some myths common about Asian
Americans. She said, “There’s a perception that Asian Americans in
particular aren’t practicing sexually risky behaviors. But we found that
Asian American young women are at risk of high STDs. For instance, Asian
American women had a highe... 阅读全帖
s*****n
发帖数: 994
6
来自主题: CS版 - Why this not working?
std::set s1, s2;
// Fill in s1 and s2 with values
std::set result;
std::set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), result.begin());
And why have to do this?
std::set s1, s2;
// Fill in s1 and s2 with values
std::set result;
std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),
std::inserter(result, result.end()));
g*********s
发帖数: 1782
7
来自主题: Programming版 - RH3/RH4上cout默认格式问题
#include
#include
#include
#include
int main(){
float f = 0.0001;
printf("f = %f\n", f);
printf("f = %g\n", f);
printf("f = %e\n", f);
std::cout <<"f = "< std::cout.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield);
std::cout <<"f = "< }
RH3:
f = 0.000100
f = 1e-04
f = 1.000000e-04
f = 1e-04
f = 1e-04
RH4:
f = 0.000100
f = 0.0001
f = 1.000000e-04
f = 0.0001
f = 0.0001
有啥办法统一格式么?机器是RH3/RH4都有。改程序也
k*****l
发帖数: 177
8
来自主题: Programming版 - cout 没有输出, 请教
代码如下:
#include
#include
#include
#include
using namespace std;
class XX
{
public:
std::string aa;
std::string pp;
std::string cc;
XX(){}
};
typedef std::vector < XX > PC;
void YY(PC& pp2cc)
{
pp2cc.clear();
for(int i=0; i<5; ++i)
{
XX temp;
std::istringstream isl(" AA BB CC");
isl >> temp.aa >> temp.pp >> temp.cc ;
pp2cc.push_back(temp);
}
}
void printGG(const PC& pp2cc)
{
std::c
d****p
发帖数: 685
9
来自主题: Programming版 - Diff between Java coder and C++ coder
不是坑,只是我自己的观察
见到如下code:
1 #include
2 #include
3 #include
4
5 typedef std::pair Property;
6
7 int main()
8 {
9 std::vector properties;
10 properties.push_back(std::make_pair("name", "foo"));
11 properties.push_back(std::make_pair("hobby", "coding"));
12 //...
13 for (std::vector::const_iterator pItr = properties.begin
();
14 pItr != properties.end(); ++pItr)
15
c*******9
发帖数: 6411
10
来自主题: Programming版 - a strange issue
I have the following existing structure:
in a header file header.h
struct test
{
test();
string a;
...
std::map b;
...
}
the existing code impl.cxx use this structure and work ok, now I modify
the structure as following in the header.h
struct test
{
test();
string a;
string a2;
...
std::map b;
...
}
and it crash now in impl.cxx in the existing code:
test test1;
..
test1.a2 = d; (crash here)
...
EXCEPTION_ACCES... 阅读全帖
A**u
发帖数: 2458
11
来自主题: Programming版 - namespace 问题
#include
#include
using namespace std;
namespace S{
class A{
};
void swap(const A& x, const A& y){
std::cout << "A swap" << std::endl;
}
}
int main()
{
S::A x;
S::A y;
swap(x,y);
//S::swap(x,y);
std::cout << "fishing" << std::endl;
return 0;
}
这个code里, namespace S里的 swap 比 std里的swap specific
为啥 gcc 编译后,调用std版本呢
X*4
发帖数: 101
12
来自主题: Programming版 - 这个dtor为啥能被调用呢
关于boost shared_ptr的,
#include
#include
#include
class A{
public:
virtual void sing() = 0;
protected:
virtual ~A(){
std::cout << "dtor of base" << std::endl;
}
};
class B: public A{
public:
virtual void sing()
{
std::cout << "DO re mi fa so la" << std::endl;
}
~B(){
std::cout << "Dtor of Derived " << std::endl;
}
};
boost::shared_ptr create(){
boost::shared_ptr
p(new B());
...
阅读全帖
k**********g
发帖数: 989
13
来自主题: Programming版 - 你妈用VS写个helloworld真难啊。
Two more tips.
(1) Precompiled header. "stdafx.h"
Basically, this is the place where you put all standard library include
directives that will be needed by your code.
Examples:
// OS includes
#include
// C includes
#include
// C++ STL includes
#include
#include
Try not to include any of your own header files in "stdafx.h", until you are
familiar with the Visual C++ build process.
Never modify "stdafx.cpp". It is required to be an empty file containing
jus... 阅读全帖
N******K
发帖数: 10202
14
来自主题: Programming版 - c++的一个诡异问题,高手请进
编译器 vs2013 release模式
Tempfunction 计算一个数然后输出 N 控制计算复杂度
我用function pointer :TempfunctionPtr = &Tempfunction
然后比较 直接调用函数Tempfunction 和 通过指针间接调用函数
结果很诡异
N=1000 , Tempfunction_time=1, TempfunctionPtr_time=2;
N=2000 , Tempfunction_time=2, TempfunctionPtr_time=6;
N=4000 , Tempfunction_time=4, TempfunctionPtr_time=11;
N=8000 , Tempfunction_time=8, TempfunctionPtr_time=21;
TempfunctionPtr_time - Tempfunction_time 应该是常数
N并不改变 函数调用的次数
=================
#include
#include
void Tempfunctio... 阅读全帖
d****i
发帖数: 4809
15
来自主题: Programming版 - C++ problem
Must be some errors in your Makefile.
I compiled using GCC 4.4 on CentOS without C++11 flag turned on. It returns
no error:
$ g++ -o dump dump.cpp
dump.cpp:
#include
#include //ostream_iterator
#include //cerr
#include //std::copy
template
void dump_to_file(const char* filename, const std::vector& v_d){
std::ofstream ofs(filename);
if(!ofs){
std::cerr<<"Unable to open the file to write!n";
return ;
}
std::... 阅读全帖
m*********n
发帖数: 28
16
来自主题: Programming版 - 该怎么设计这个类?
后面的补充想法是对的。给你个范例程序
struct SexOrgan {
};
struct Asshole : public SexOrgan {
};
struct Dick : public SexOrgan {
};
struct Pussy : public SexOrgan {
void Eat(Dick& dick) {
};
};
void B2B(Pussy& p0, Pussy& p1) {
}
struct HumanBeing {
virtual void BangWith(HumanBeing & that) {
// take off all clothes;
}
};
struct Female;
struct Male : public HumanBeing {
virtual void BangWith(HumanBeing& that) {
HumanBeing::BangWith(that);
Female* female = dynamic_cast阅读全帖
S****8
发帖数: 401
17
来自主题: Programming版 - 请教一个算法
可能是经典问题,问得太弱还请指出轻拍:)
需求描述:
-要以某种方式遍历一个N*N的2维坐标系,每个坐标点发一个请求RequestData(),返回
一个int整数,
-需要用两个vector 去记录所有x/y方向的discontinuity点的坐标
RequestData(x,y) != RequestData(x+1,y) => 就算x方向的discontinuity点(x,y)
RequestData(x,y) != RequestData(x,y+1) => 就算y方向的discontinuity点(x,y)
问题:
如何实现最优算法,以及如何高效omp并行(N很大,内存也足够大)
std::vector oRequested;
std::vector> oXdiscontinuity;
std::vector> oYdiscontinuity;
for (int x=0; x {
for (int y=0; y {
oReque... 阅读全帖
v*****s
发帖数: 20290
18
http://www.bu.edu/phpbin/news-cms/news/?de...92&id=52827
……………………
Over the course the study, Hahm unmasked some myths common about Asian
Americans. She said, “There’s a perception that Asian Americans in
particular aren’t practicing sexually risky behaviors. But we found
that Asian American young women are at risk of high STDs. For instance,
Asian American women had a higher prevalence of STDs than White women in
both 1995 (10.4% vs. 7.7) and 2001 (13.5% vs. 8.3%). The incidence of
STDs (not dia... 阅读全帖
r******t
发帖数: 629
19
俺在NJ,想不到13年的civic现在还有剩,真是令人发指啊,滞销货?
先来一个离得超近的NJ dealer A 报价
$16738+tax+TLL
过了一会儿,PA的dealer B 报价一个
$15759+tax+TLL (有学生rebate-500),其实车本身是16259,OTD价格是17,622.33
再减掉500块~
又过了一会儿,一个NJ没那么近的dealer C报价
$16738+TLL
我不禁怀疑,NJ dealer都是统一价格……望天,反正我让dealer C去beat dealer B了
,目前没结果……
对于dealer互相凶残的结果我还是小小的期待一下下的~
等我收到,我就会来汇报的~
不知道这价格是不是已经可以下手了?
我看了看板子上最近的Civic 2013 LX auto的成交记录:
去年6月: OTD18500,有500的graduate rebate
去年12月:报价17K, OTD,Virginia,还有¥17,600 DRIVE OUT,HOUSTON
去年12月:NJ OTD 18300
去年12月:$16,800 + ttl,OTD 1850... 阅读全帖
l*******g
发帖数: 4894
20
来自主题: JobHunting版 - 发个题目给大家复习一下marco
#define sqrt(x) x*x
int main(){
int i=4;
std::cout< std::cout< std::cout< }
c*****e
发帖数: 737
21
来自主题: JobHunting版 - 一道面试题
find:9006221 points.
1 #include
2 #include
3 #include
4 #include
5
6 typedef std::pair Cord;
7 typedef std::map Cords;
8
9 Cords cords;
10 int total = 0;
11
12 bool findCord(int x_, int y_)
13 {
14 if (cords.find(std::make_pair(x_, y_)) != cords.end()) return true;
15 return false;
16 }
17
18 int count(int x_)
19 {
20 int x ... 阅读全帖
j*****y
发帖数: 1071
22
来自主题: JobHunting版 - leetcode 的编译器是旧的还是新的?
我的电脑的是 g++ 4.4.3 ,编译下面的代码可以过,但是 leetcode过不了
定义了一个 函数
bool comp(const pair & a, const pair & b);
然后有个 vector > v;
然后调用 sort(v.begin(), v.end(), comp);
我的电脑可以编译。 但是 leetcode给了这个错误
no matching function for call to 'sort(std::vector basic_string > >::iterator, std::vector string > >::iterator, )
s***b
发帖数: 139
23
来自主题: JobHunting版 - 请问下leetcode的two sum题目
下面的程序如果用了注释部分,对于相等的key的处理就有错,如果不用注释部分,就
没错,不知道哪位大牛能解释下为什么啊?谢谢
Ex: 比如array = [2,1,9,4,4,56,90,3], target = 8,正确输出应该是4,5
如果定义hash table是用的是:table[numbers[i]] = i 那就能正确输出
如果定义用的是:table.insert(std::make_pair(numbers[i], i)); 那就
会输出4,4
对此十分不理解啊,不是同样的插入么?unordered_map是怎么处理key相等的状况的,
一般来说key不是unique的么?万分感谢啊!!!
class Solution {
public:
std::vector twoSum(std::vector &numbers, int target) {
std::vector result;
std::unordered_map table;
for(unsigned int i =... 阅读全帖
r*c
发帖数: 167
24
来自主题: JobHunting版 - 问一道题(6)
贴个pattern字符串有重复字符的解法, 是dek,cpp1等大牛的解法的扩展。
#include
#include
#include
#include
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
class MinWindowSolution
{
public:
struct TreeNode
{
TreeNode *parent;
int val;
vector children;
TreeNode(int i, TreeNode *p) : val(i), parent(p){}
};
void FindMinWindow_Tree(const vector& input , const vector&
query , int& nStart,... 阅读全帖
S********e
发帖数: 74
25
来自主题: JobHunting版 - 问个 matrix 的问题 (CS)
铁一下这个算法的code
int maxSub(std::vector > &matrix)
{
std::vector store(matrix.size(),INT_MAX);
int max_sub=INT_MIN;

for (int r=1; r {
for (int c=1; c {
store[c]=std::min(matrix[r-1][c-1],std::min(store[c-1],store[c])
);
max_sub = std::max(max_sub,matrix[r][c]-store[c]);
}
}
return max_sub;
}
p********4
发帖数: 58
26
来自主题: JobHunting版 - c++疑难问题。。
我的理解,应该在vector中放地址,而不是object本身。这样才能实现多态。你原来的
做法,你的y中都是 class A. 不知道我的理解对不对。
int main()
{
const A a(1);
const B b(3);
const A *x[2] = { &a, &b };
typedef std::vector V;
V y({ &a, &b });
std::cout << x[0]->f() << x[1]->f() << std::endl;
for (auto i : y)
{
std::cout << i->f();
}
std::cout << std::endl;
return 0;
}
output:
14
14
y******k
发帖数: 1
27
来自主题: JobHunting版 - 一到面试题 弱弱求解答
Consider two time series. Each time series contains price and time. Time is
expressed in number of seconds since market open. Every time when price
changes – there is a new entry into time series. Write a program that
receives two inputs: time series 1 and 2, and calculates another time series
containing the price difference (spread) between the two products at fixed
10 seconds interval.
//Each timeseries in represented as a key-value object, where keys are times
and values are prices.
//We simp... 阅读全帖
z**a
发帖数: 237
28
来自主题: NextGeneration版 - 请问加州的姐妹们一个关于产假的问题
如果公司没有特别的maternity leave, 只有STD, 有什么办法可以用足STD? 员工手册
上说我们公司是13周100%工资+12周70% 的STD.但我们办公室前几个休产假的都是休息3
个月就上班了。我是打算从怀孕第8个月开始就休假,加上自己的年假应该可以凑满半
年,主要是不想大肚子了还要冰天雪地地开车去公司外加一周70小时的忙季加班,只是
不知道能不能全部利用到STD?
有知道的jms可以说说你们都是怎么用足STD的?问过医生,他好像说产前2周休息就差
不多了,不建议我提前3个月就在家待产,难道STD都要医生批准才行?
w*********r
发帖数: 151
29
EDD 网站上有关于BASE PERIOD的详细解释。应该差不多是你工资的55%。 http://www.edd.ca.gov/disability/DI_Benefit_Amounts.htm
这个可能是公司的规定。 我记得以前是有12个月的规定的,可是我没有在EDD的网站上
找到相关的条款。只看到这一条:You must have earned at least $300 from which
SDI deductions were withheld during a previous period. (具体ELIGIBILITY的规
定请参考http://www.edd.ca.gov/disability/DI_Eligibility.htm
我知道产后6周是肯定的。有一周的WAITING PERIOD. 具体产前几周不是很确定,你可
以在查查它的网站。
我的理解是如果你被批准了STD,那么你自动地QUALIFY PFL. STD结束后,它们会给你
寄PFL的表格,你填好后交上去就行了。PFL的PAY好像和STD是一样的,工资的55%, 但
要缴税。
不管怎样都应该试一试. 说... 阅读全帖
az
发帖数: 16686
30
来自主题: NextGeneration版 - 一个字累
保胎的是产前的STD,一样的规则,第一周自己负责,下面60%工资,STD是多久来着,
有上限的,不够了就LTD吧,但是怀孕STD足够了吧。我生老大用了蛮多产前的STD,产
前用多少跟产后没关系的,产前的叫medical的STD,产后是maternity的STD
l*********e
发帖数: 5385
31
☆─────────────────────────────────────☆
sunflower33 (我也来了) 于 (Mon Dec 3 09:27:46 2012, 美东) 提到:
Boy or girl:
Yes or no?
Why yes?
Why no?
自己也有些confusion, 故看看大家的态度,谢谢
☆─────────────────────────────────────☆
mimyw (小猫子:3) 于 (Mon Dec 3 09:29:57 2012, 美东) 提到:
Boy,
Yes,
cuz that's what daddy wants. also easy to keep clean.
☆─────────────────────────────────────☆
lightgreen (四月芽) 于 (Mon Dec 3 09:42:02 2012, 美东) 提到:
Boy
Yes
Easy to clean, low risk of infection.

★ 发自iPhone App: ChineseW... 阅读全帖
R*******n
发帖数: 428
32
来自主题: Badminton版 - 伪币
> it looks linear in terms of Dan, but it says nothing of the actual
> level of play, since there is no numeric measurement.
I proposed a numeric measurement, the number of points lost in a game, but
you choose to ignore it, and claim there is no numeric measurement.:)
Actually, many Korean weiqi players use this system when they gamble. 1
point equal to $10. I watched one guy lose $300 in one night (3 games).
For badminton, if I play with Lin Dan, I will probably get 1 point in a game
by hittin... 阅读全帖
t******n
发帖数: 2939
33
☆─────────────────────────────────────☆
slmxx (slmxx) 于 (Tue Jan 31 16:08:36 2012, 美东) 提到:
自从日本战败后整个东亚沦为西方的小妾,于是外F洪流浩浩汤汤,一直到今天,从纽
约到温哥华,从洛杉矶到东京,从上海到北京,外F已形成世界性的潮流,任何一个白
男都可以纵横于亚女(尤其是国女)中无数,夜夜新郎,撕扯着wsn们的心 。而外F女
们的成功概率实际很有限,本人听过美国fetish白男谈过说他对亚女很着迷但只愿意用
来F玩玩,真正娶妻生子还是要白女,因为毕竟文化和生活习惯一致。
于是在北美很多国女外F失败后遂寻求wsn接盘,而如今很多wsn学精了宁肯搬运都不愿
理会外F女,于是很多外F国女们也开始百般伪装来顺利找到接盘对象,敲诈猥琐男们的
剩余价值。这类外F女们在面对老外男人们时候风骚异常三口全开而回来面对wsn的时候
却又变成了翩翩淑女,言性而赧。很多没有社会经验的wsn最后便悲剧地成为了外F失败
女们的接盘仆人和长期饭票,牛马一生。
本人在美国也待了有些年头了,听闻了身边很多外F女的故事,... 阅读全帖
s***e
发帖数: 122
34
来自主题: CS版 - 问一个c++问题
那最好还是定义一个自己的输出输入类吧。这样以后万一修改代码的时候也不容易漏掉
。刚才写了一个例子,也是做个练习,呵呵,以前也没有自己写过。你就作为一个参考
吧。
// MyIn.h
#ifndef _MY_IN_H_
#define _MY_IN_H_
#include
#include
#include
class MyIn
{
private:
std::ofstream& ofs;
public:
MyIn(std::ofstream& o);
public:
MyIn& operator >> (int& i);
MyIn& operator >> (std::string& s);
};
#endif
// MyIn.cpp
#include "MyIn.h"
MyIn::MyIn(std::ofstream& o):ofs(o) {
}
MyIn& MyIn::operator >> (int& i) {
std::cin >> i;
ofs << i << std::endl;
return *this;
}
u**********e
发帖数: 282
35
来自主题: Programming版 - 大家帮忙看看是什么问题
好久没用C++了,都忘光了。
大家帮忙解释一下下面ERROR是怎么回事
1.1 typedef std::wstring TLogicalIdentity;
1.1 typedef std::pair TLogicalKey;
1.1 typedef std::pair TExternalData;
1.1 typedef std::vector TEntryList;
1.1 typedef std::map TPerIdentityStatus;
1.1 typedef std::map
TIdentityStatus;
gcc3.4.5
In file included from ../../../DevTests/AssociativeCont
S*******s
发帖数: 13043
36
来自主题: Programming版 - where to define my template function
in my project, I have following 3 files
//t.h
#include
template
myFunc (std::vector& var){
....
}
//a.cpp
#include "t.h"
void funcA(){
std::vector a;
std::vector b;
myFunc(a);
myFunc(b);
}
void funcB();
int main(){
funcA();
funcB();
}
//b.cpp
#include "t.h"
void funcB(){
std::vector a;
std::vector b;
myFunc(a);
myFunc(b);
}
if I build it, I'll get an error that myFunc(std::vector&) defined
twice.
if I manage them in di
s***e
发帖数: 793
37
来自主题: Programming版 - 来,做题吧。
发信人: shaye (wonderfull), 信区: JobHunting
标 题: Re: 来,做题吧。
发信站: BBS 未名空间站 (Sun Nov 11 04:32:21 2007)
原来写过一个,应该work
bool nextPermutation(char* a, int n){
int pos=n-1;
while(pos>0 && a[pos]<=a[pos-1]) pos--;
if(pos==0)return false;
int s=pos;
int e=n-1;
while(e>s){std::swap(a[s],a[e]),s++;e--;}
for(int i=pos;i if(a[i]>a[pos-1]){
std::swap(a[i],a[pos-1]);
break;
}
return true;
}
void printAllPermutation(char* a, int n){
std::sort(a,a+n);
std::cout< while(nextPermutation(a,n)) std
g*********s
发帖数: 1782
38
来自主题: Programming版 - 再问两个C++问题
1.这个代码输出为何是0 1 10 2 4,而不是0 1 10 3 4?
#include
#include
#include
int main(){
std::vector v;
for (int i=0; i<5; i++){
v.push_back(i);
}
v.erase(std::find(v.rbegin(), v.rend(), 2).base());
v.insert(std::find(v.rbegin(), v.rend(), 1).base(), 10);
std::copy(v.begin(), v.end(), std::ostream_iterator(std::cout, " ")
);
return 0;
}
2. 这段代码里为何String s1('a')和String s1='a'不等价?
class String{
public:
explicit String(char c, int
x*********h
发帖数: 25
39
来自主题: Programming版 - one question about operator delete
Hi, I have a question about operator delete, dtor.
define a class like below,
class TestDelete{
public:
virtual ~TestDelete(){
std::cout << "TestDelete::~TestDelete" << std::endl;
}
void operator delete (void* p){
std::cout << "TestDelete::operator delete()" << std::endl;
}
// void operator delete[] (void* p){
// std::cout << "TestDelete::operator delete()" << std::endl;
// }
};
then, write statements like :
TestDelete* p = NULL;
delete p;
I found
r****t
发帖数: 10904
40
奇怪,在连接的时候遇到如下错误,-lstdc++ 也没法成功,怎么办?
undefined reference to `operator<<(std::basic_string char>, std::allocator >&, int)'
undefined reference to `operator<<(std::basic_string char>, std::allocator >&, int)'
collect2: ld returned 1 exit status
c*****t
发帖数: 1879
41
#include
using namespace std;
class A
{
private:
int m_value;
public:
A (int v) : m_value (v) { std::cout << "ctor" << std::endl; }
~A () { std::cout << "dtor" << std::endl; }
int getValue () { return m_value; }
};
#define SIZE 10
int main ()
{
// init
A* array = (A*)new char[sizeof (A) * SIZE];
for (int i = 0; i < SIZE; ++i)
new (&array[i]) A (5);
for (int i = 0; i < SIZE; ++i)
std::cout <
g****g
发帖数: 310
42
来自主题: Programming版 - C++中virtual function的性能差是个误解
Hey, are you using a computer of year 1995???
It's quite outdated. You should write code and test yourself. Easy job:
class Base
{
public:
virtual void say()
{
std::cout<<"say";
}
Base()
{
std::cout<<"Base";
}
~Base()
{
std::cout<<"~Base";
}
};
class Base2
{
public:
void say()
{

b=rdtsc()-a;
std::cout << "Take:" << b << std::endl;
}
Base2()
{
std::cout<<"Base2";
}
~Base
L*******s
发帖数: 63
43
来自主题: Programming版 - 请教sgi hash_map
编译器好像是 g++ 4.3.4
struct eqstr
{
inline bool operator()(const char* s1, const char* s2) const
{
return 0 == strcmp(s1, s2);
}
};
typedef __gnu_cxx::hash_map >, eqstr> MyTable;
现在有
MyTable t;
中途进行一系列添加操作
每隔一段时间进行以下输出
std::cout << t.size() << std::endl;
std::for_each(t.begin(), t.end(), display1);
display1如下:
void display1(std::pair pr)
{
std::cout << (pr.second ? "T " : "F ") << pr.first << std::endl;
}
我现
e**********n
发帖数: 359
44
#include "temp.hh"
#include
main() {
StringSet constStrs;
for(StringSet::iterator it = constStrs.begin(); it!=constStrs.end();
it++) {
std::cout << *it <<" ";
}
}
其中 “temp.hh" 为:
#include
#include
class StringSet : public std::set {
public:
StringSet(){
insert( std::string("0"));
insert( std::string("1"));
......
insert( std::string("3999"));
};
};
总共往StringSet里添加了4000个字符串,此处为了简单用0到3999,但实际上可以是任
意的字符串。
用 g++ -g 编译很快完事
h****e
发帖数: 2125
45
来自主题: Programming版 - 如何在c++里定义一个map of map

something similar?
to store in a custom list class that internally holds them in a
std::map. The definition of this map within my list class is:
instances of std::shared_ptr that I add to to m_cvars go out
of scope as soon as the function I happen to be in when I add them
finishes. I've tried multiple ways to do this, including:
minVal, hasMax, maxVal));m_cvars[var_name] = cv;/* AND
*/m_cvars[var_name] = std::make_shared(ARGUMENTS FOR
VARIABLE());
std::shared_ptrs with diffe... 阅读全帖
C**m
发帖数: 126
46
来自主题: Programming版 - c++ singleton questions
#include
#include
class X {
public: X* get_X();
private:
static X _x;
};
X X::_x;
X* X::get_X()
{
return &_x;
}
int main(int argc, char* argv[])
{
X *p;
std::cout << "the address " << (void *) p->get_X() << std::endl;
X a;
std::cout << "the address " << (void *) a.get_X() << std::endl;;
X b;
std::cout << "the address " << (void *) b.get_X() << std::endl;;
return 0;
}
/... 阅读全帖
C**m
发帖数: 126
47
来自主题: Programming版 - c++ singleton questions
#include
#include
class X {
public: X* get_X();
private:
static X _x;
};
X X::_x;
X* X::get_X()
{
return &_x;
}
int main(int argc, char* argv[])
{
X *p;
std::cout << "the address " << (void *) p->get_X() << std::endl;
X a;
std::cout << "the address " << (void *) a.get_X() << std::endl;;
X b;
std::cout << "the address " << (void *) b.get_X() << std::endl;;
return 0;
}
/... 阅读全帖
L*******s
发帖数: 63
48
来自主题: Programming版 - C++ syntax question
Might be a stupid question...:
Why
std::string sContent((std::istreambuf_iterator(fi)),
std::istreambuf_iterator());
doesn't work, but
std::string sContent(std::istreambuf_iterator(fi),
std::istreambuf_iterator());
works? Thanks a lot!
H****r
发帖数: 2801
49
来自主题: Programming版 - question about c++ constructor

这个 "C++ temporary object can not be bound to non-const reference" 俺似乎理解
了,但是楼主的例子在VS2010 下并没有报错啊?
class M{
public:
int i;
public:
M(){ std::cout << "default constructor" << std::endl;}
M(int ii):i(ii){ std::cout << "constructor"<< std::endl;}
M(M & mm):i(mm.i){ std::cout << "copy constructor"<< std::endl;}
};
int main()
{
M mm = 1;
}
其中 M(M & mm):i(mm.i) 改成 M(const M & mm):i(mm.i) 并没发现对 M mm = 1; 有
任何影
响啊。
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)