//: C02:Effector.txt
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// (Should be "cpp" but I can't get it to compile with
// My windows compilers, so making it a txt file will
// keep it out of the makefile for the time being)
// Jerry Schwarz's "effectors"
#include<iostream>
#include <cstdlib>
#include <string>
#include <climits> // ULONG_MAX
using namespace std;
// Put out a portion of a string:
class Fixw {
string str;
public:
Fixw(const string& s, int width)
: str(s, 0, width) {}
friend ostream&
operator<<(ostream& os, Fixw& fw) {
return os << fw.str;
}
};
typedef unsigned long ulong;
// Print a number in binary:
class Bin {
ulong n;
public:
Bin(ulong nn) { n = nn; }
friend ostream& operator<<(ostream&, Bin&);
};
ostream& operator<<(ostream& os, Bin& b) {
ulong bit = ~(ULONG_MAX >> 1); // Top bit set
while(bit) {
os << (b.n & bit ? '1' : '0');
bit >>= 1;
}
return os;
}
int main() {
char* string =
"Things that make us happy, make us wise";
for(int i = 1; i <= strlen(string); i++)
cout << Fixw(string, i) << endl;
ulong x = 0xCAFEBABEUL;
ulong y = 0x76543210UL;
cout << "x in binary: " << Bin(x) << endl;
cout << "y in binary: " << Bin(y) << endl;
} ///:~
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
thinking c++ 习题答案 (415个子文件)
ExtractCode.cpp 23KB
SequencePerformance.cpp 5KB
Cppcheck.cpp 4KB
ObservedFlower.cpp 4KB
MemCheck.cpp 4KB
BitSet.cpp 4KB
Recycle2.cpp 3KB
BankTeller.cpp 3KB
Recycle1.cpp 3KB
SearchReplace.cpp 3KB
FunctionObjects.cpp 3KB
Persist2.cpp 3KB
Rtshapes.cpp 3KB
TrashVisitor.cpp 3KB
Recycle2.cpp 3KB
PaperScissorsRock.cpp 3KB
SortTest.cpp 3KB
ShapeFactory2.cpp 3KB
BasicSequenceOperations.cpp 3KB
WildLifeMonitor.cpp 3KB
ReprocessHTML.cpp 3KB
VirtualConstructor.cpp 3KB
Manipulations.cpp 3KB
Showerr.cpp 3KB
Selfrtti.cpp 2KB
BeeAndFlowers.cpp 2KB
SiteMapConvert.cpp 2KB
mlm.cpp 2KB
Ring.cpp 2KB
Thesaurus.cpp 2KB
Format.cpp 2KB
ExtractUndeliverable.cpp 2KB
Batchmail.cpp 2KB
TokenIteratorTest.cpp 2KB
Datascan.cpp 2KB
Breakup.cpp 2KB
StringDeque.cpp 2KB
AbstractFactory.cpp 2KB
Manips.cpp 2KB
ShapeFactory1.cpp 2KB
CLib.cpp 2KB
Comparison.cpp 2KB
Persist1.cpp 2KB
Recycle4.cpp 2KB
CppLib.cpp 2KB
MultiSet1.cpp 2KB
Bicycle.cpp 2KB
Cleanup.cpp 2KB
AssociativeBasics.cpp 2KB
PriorityQueue6.cpp 2KB
Datalog.cpp 2KB
ListSpecialFunctions.cpp 2KB
PriorityQueue7.cpp 2KB
MapVsHashMap.cpp 2KB
ProgValTest.cpp 2KB
InnerClassIdiom.cpp 2KB
Menu.cpp 2KB
NewFind.cpp 1KB
DoubleDispatch.cpp 1KB
Wrapped.cpp 1KB
DynaTrash.cpp 1KB
NumericTest.cpp 1KB
Inserters.cpp 1KB
Sorted.cpp 1KB
Removing.cpp 1KB
ListVsSet.cpp 1KB
Stack2.cpp 1KB
Sieve.cpp 1KB
Rparse.cpp 1KB
VectorOfBool.cpp 1KB
PriorityQueue3.cpp 1KB
Mathops.cpp 1KB
Mithis.cpp 1KB
IndexingVsAt.cpp 1KB
SetOperations.cpp 1KB
Paste.cpp 1KB
Datagen.cpp 1KB
HTMLStripper.cpp 1KB
ProgVals.cpp 1KB
SortedSearchTest.cpp 1KB
MultipleInheritance4.cpp 1KB
Strfile.cpp 1KB
CLibTest.cpp 1KB
MultipleInheritance3.cpp 1KB
Recycle3.cpp 1KB
Stlshape.cpp 1KB
OnTheFly.cpp 1KB
static_cast.cpp 1KB
SpecialList.cpp 1KB
CppLibTest.cpp 1KB
Stlshape2.cpp 1KB
StrSize.cpp 1KB
ListStability.cpp 1KB
fillBin.cpp 1KB
Swapping.cpp 1KB
NoCompose.cpp 1KB
Specify.cpp 1KB
WordList2.cpp 1KB
Nudep.cpp 1020B
Stack1.cpp 1018B
共 415 条
- 1
- 2
- 3
- 4
- 5
资源评论
knowline
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功