A puzzle for me (cookie)
2014-01-02 16:28
253 查看
Today, i met a problem.. I'm a new man in C++ programer.
So it's reserved for me... I believe I would get it.
if we input "abc", the console return the 'a'.. the next time, we input the "jame", the console return the 'a'.. why ?
Let's made some changes in this program!
what you got? the first element in str. why?
Let's make more changes.
what do we get? the same behavior as the second one.
So it's reserved for me... I believe I would get it.
#include <iostream> using nameapce std; int main(){ string str; auto sp = str.begin(); /// str.begin()?? while (cin >> str) { cout << *sp << endl; } }
if we input "abc", the console return the 'a'.. the next time, we input the "jame", the console return the 'a'.. why ?
Let's made some changes in this program!
#include <iostream> using namespace std; int main(){ string str; while(cin >> str) { auto sp = str.begin(); /// place it in the different place. cout << *sp << endl; } }
what you got? the first element in str. why?
Let's make more changes.
#include <iostream> using namespace std; int main(){ string str, *sp; sp = &str; while ( cin >> str){ // remove the str.begin(), replaced with string pointer. cout << (*sp)[0] << endl; } }
what do we get? the same behavior as the second one.
相关文章推荐
- Android development - 'missing theme error' in eclipse ide for layout xml files
- HDU 1538 A Puzzle for Pirates 海盗分金问题
- Easy 118题 Pascal's Triangle (may be not easy too for me)
- theme editor for wordpressmu
- MakeFile Implicit Rules,A Gift for Me(强大的MAKEFILE)!!!
- The First Blog For Me
- C#: Writing a CookieContainer to Disk and Loading Back In For Use
- 博弈学习(三) HDU 1538 A Puzzle for Pirates(经典的海盗分金推理)
- Missing styles. Is the correct theme chosen for this layout?
- android xml 布局错误(黑掉了)Missing styles. Is the correct theme chosen for this layout?
- Temporary Post Used For Theme Detection (e7e71fb9-e8e0-4c6c-90a1-5195958abe5b - 3bfe001a-32de-4114-a6b4-4005b770f6d7)
- HDU 1538 A Puzzle for Pirates
- Java Puzzlers笔记--Puzzle 2: Time for a change 关于浮点型的问题
- It is time for me to continue the contract with company
- 【HDU1538】A Puzzle for Pirates(经典的海盗问题)
- ReadMe for Message Handlers and Scheduler Tutorial
- for me
- effective C++之mixin风格的base class(怪异的循环模板模式,又称do it for me)
- 两件大事 just for me
- 贝瓦电台下载 听腻了情啊爱啊,听听童歌吧,so suite for me.what about you..