http://www.51testing.com/?uid-202848-action-viewspace-itemid-242043
posted @ 2012-05-20 17:28 children 阅读(9) 评论(0) 编辑
http://dongwenbo.blog.51cto.com/506198/538860
posted @ 2012-05-20 16:44 children 阅读(8) 评论(0) 编辑

cin:

当碰到空格或换行符'\n'时,输入结束:

char a[10],b[10];

cout<<"Enter some input:\n";

cin>>a>>b;

cout<<a<<b<<"End\n";

输出结果为:

Enter some input:

12 34 56

1234END

 cin.getline:

当碰到换行符'\n'或达到所能接受的最大字符数时,输入结束:

char a[10];

cout<<"Enter some input:\n";

cin.getline(a,5);

cout<<a<<b<<"End\n";

输出结果为:

Enter some input:

123456

1234END

需要注意的是,a读入了4个字符,不是5个,是因为'\0'占了一位

 cin.get:

可以读入任何字符,包括空格和'\n':

cout<<"Enter some input:\n";

char a,b,c;

cin.get(a);cin.get(b);cin.get(c);

cout<<a<<b<<c<<"End\n";

 

输出结果为:

Enter some input:

AB

CD

那么a的值为'A',b的值为'B',c的值为'\n\

 

 

注意:

    在使用get时,必须考虑空格和换行符的处理: 

int n;char c;

cout<<"Enter a number:\n";

cin>>n;

cout<<"Now enter a letter:\n";

cin.get(c);

输出结果为:

Enter a number:

10

Now enter a letter

 

n的值顺利读入10,但c的值为'\n',因为读入数字10后,输入流中下一个被读取的字符是'\n'

 

 

posted @ 2012-05-15 17:46 children 阅读(3) 评论(0) 编辑

char cString[10]="hello world" 是初始化,合法。

 

char cString[10];

cString="hello world" 是赋值,这样赋值非法。原因在于声明了cString数组后,cString其实是一个char型的常量指针,而cString="hello world" 一句的意思是将常量"hello world"的首地址赋给cString,这与cString指针的常量属性冲突。

可以用strcpy(cString, "hello world")的方法来赋值,但要注意检查cString空间是否足够

posted @ 2012-05-15 13:21 children 阅读(5) 评论(0) 编辑

posted @ 2012-05-15 10:56 children 阅读(2) 评论(0) 编辑

    如果希望函数的返回对象可以作为左值(能够出现在赋值操作符左边的值或表达式),那么函数必须返回引用类型。

    但当某个类的成员函数要返回类类型的成员变量,就不能返回引用类型。

    通常,要返回类类型的成员变量时,一般需要返回常量类型。

posted @ 2012-05-15 10:51 children 阅读(4) 评论(0) 编辑

    将二元操作符重载为成员函数时,两个参数(即操作数)就不再是对等,第一个参数成为了调用对象,第二个参数成为真正的参数。比如下面的语句合法:

    Money baseAmount(100,60),fullAmount;

    fullAmount=baseAmount+25;

    这是因为Money类包含了一个带int型参数的构造函数,因此25会自动转换为Money类的对象。但加号两边的参数不能互换。

 

    将二元操作符重载为非成员函数时,两边参数可以互换,但效率没重载为成员函数时的高,而且函数内不能直接读取private成员。

 

 

     重载为友元函数的话,既可直接访问private成员,有课互换参数

posted @ 2012-05-15 10:42 children 阅读(2) 评论(0) 编辑

假设有一对象:

var obj={
  name:'ldg',
  age:25,
  var:'test'
}

如果直接用obj.var去读属性var 的话,在ie会不通过,因为var是关键字。可以改用obj["var"]或者obj[2]的方式读取 ,或者用反射的方式读取:

for(var p in obj){

  alert(obj[p]);

 

posted @ 2012-05-08 11:09 children 阅读(0) 评论(0) 编辑

正常情况下,jQuery 的 $.get/$.ajax 方法是不能跨域访问别的网站资源的,解决方法如下:

 

一些有用的链接:

http://blog.csdn.net/jallin2001/article/details/5663748

http://www.jb51.net/article/21213.htm

http://sonyfe25cp.iteye.com/blog/609725

 

实践得出最后可行的代码(ff和ie):

 

 

 $(document).ready(function() { 

     var url=‘....’;
     //注意,是callback,而不是jsoncallback
     $.getJSON(url+"&callback=?", function(data) {
           var length=data.length;  
     });

})

 

 

 

posted @ 2012-05-04 16:58 children 阅读(2) 评论(0) 编辑
posted @ 2012-04-17 11:49 children 阅读(4) 评论(0) 编辑