CodeSky 代码之空

随手记录自己的学习过程

归档时间:2014-09

C (bu)科学的复数求解(两数加减乘除)

2014-09-26 19:43分类: C评论: 2

这次真的是记录一下思考过程了,反正是个很坎坷复杂的经历。 github地址:https://github.com/csvwolf/Sky-C-Study/tree/master/数据结构 老师给了我们一个结构体的框架,不得不说C的结构体和C++的还是有差别的:http://www.cppblog.com/percyph/archive/2009/03/06/75742.html

由此,我们这样定义一个结构体之后:

1typedef struct
2{
3    float rpart;
4    float ipart;
5} complex;
6
阅读更多 →

C++ string型初识与getline

2014-09-26 17:29分类: Other评论: 2

string比C语言好用多了。只要引入一个#include <string>以及using std::string;就OK了,其他部分真是像极了其他的语言,一些用法可以看注释,getline就和gets差不多一个意思,但没有数组自然也没什么风险吧。大致是酱紫的。

1#include <iostream>
2#include <string>
3using std::string;
4using std::cin;
5using std::cout;
6using std::endl;
7
8int main()
9{
10	string line;
11	string s1 = "Hello", s2 = " World";
12	string s3 = s1 + s2;
13	cout << s3 << endl;
14	while (getline(cin, line))
15		/* 如果不为空 */
16		//if (!line.empty())
17		/* 输出大于10字符的行 */
18		if (line.size() > 10)
19			cout << line << endl;
20		
21	/*
22	while (cin >> word)
23		cout << word << endl;
24	*/
25	return 0;
26}
27
阅读更多 →

C++ 命名空间的using声明

2014-09-26 16:49分类: Other评论: 0

C++中,老师上课说的一直有一句:using namespace std;,不过他是什么意思,其实也就是一个命名空间的概念,概念这东西不多说(Primer 74页)

我们为什么要使用命名空间,不使用会有什么麻烦。 这里我们看一段代码:

1#include <iostream>
2
3int main()
4{
5	std::cout << "Enter two numbers:" << std::endl;
6	int v1 = 0, v2 = 0;
7	std::cin >> v1 >> v2;
8	std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1 + v2 << std::endl;
9
10	return 0;
11}
12
阅读更多 →

C++ auto decltype 初始化变量类型

2014-09-26 16:43分类: Other评论: 0

C++中的两种有趣的类型,让编译器自己去分析我们所需要的数据类型,这两者有有些区别: auto 定义的变量必须具有初值

1// 由val1和val2相加的结果可以推断出item的类型
2auto item = val1 + val2;  // 初始化为val1和val2相加的结果
3

但是,注意以下两条:

1auto i = 0, *p = &i;   // 正确:i是整数,p是整型指针
2auto sz = 0, pi = 3.14;  // 错误,sz和pi的类型不一致
3

具体的,Primer61页之后有,稍微看下就好了,关于类型都是个麻烦的东西。

阅读更多 →

git push本地代码到github出错

2014-09-20 18:36分类: Other评论: 0

用谷歌反倒没找到能看懂的……转自:http://www.douban.com/note/332510501/

刚创建的github版本库,在push代码时出错:

$ git push -u origin master
To [email protected]:******/Demo.git
 ! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

网上搜索了下,是因为远程repository和我本地的repository冲突导致的,而我在创建版本库后,在github的版本库页面点击了创建README.md文件的按钮创建了说明文档,但是却没有pull到本地。这样就产生了版本冲突的问题。

阅读更多 →

C 清空键盘缓冲区若干方法

2014-09-19 19:29分类: C评论: 0

写这次的数据结构的作业的时候对于缓冲区问题深表蛋疼,getchar()深表拙计,于是搜了一下……

以下文字来自:http://www.ludou.org/c-clear-buffer-area.html

清空键盘缓冲区很多种方法,如用fflush(stdin); rewind(stdin);等,但是在linux这些都不起作用,还得我今天试了半天都没成功,上网搜了一下发现setbuf(stdin, NULL);就能直接清空键盘缓冲区了。

以下几个实例:

Sample one

1#include <stdio.h>
2
3int main()
4{
5    char ch1;
6    char ch2;
7
8    ch1 = getchar();
9    ch2 = getchar();
10    printf("%d  %d", ch1, ch2);
11    return 0;
12}
13
阅读更多 →

Tumblr MarkDown 语法

2014-09-11 21:54分类: Other评论: 0

最近在用Tumblr和Twitter学习英文,然后发现Tumblr的markdown语法虽然相近,还是有些功能没有的,大致写一下。

转自我的Tumblr:Tumblr MarkDown Syntax

Something different from my uses before.

All below can be realized by HTML.

阅读更多 →
共 9 篇文章,1 页