注册 登录
编程论坛 C++教室

一个简单的问题。

有容就大 发布于 2012-07-24 12:18, 967 次点击
程序代码:
#include <iostream>
using namespace std;

int main(void)
{
    cout <<

    system("pause");

    return 0;
}
大家不去上机试 看看上面这个代码能不能执行?
21 回复
#2
有容就大2012-07-24 12:22
#include <iostream>
using namespace std;
 
int main(void)
{
    cout << /*"/***/"*/;
 
    system("pause");
 
    return 0;
}

还有这个呢 不试直接说 能不能执行?
#3
peach54602012-07-24 12:55
你说能不能执行呢?
#4
有容就大2012-07-24 13:00
回复 3楼 peach5460
呵呵 我试过了 是来考考大家的
#5
跳跳鱼2012-07-24 13:55
回复 4楼 有容就大
第一个能执行,第二个不能执行诶!为什么呢?
#6
有容就大2012-07-24 14:10
回复 5楼 跳跳鱼
是啊 为什么呢? 具体机理还真不好说。
#7
liudw22012-07-24 15:49
#include <iostream>
using namespace std;

int main(void)
{
    cout << /*"/***/"*/; 你都用注释包括了,还怎么输出,最主要是后面跟着的分号。。

    system("pause");

    return 0;
}

#8
liudw22012-07-24 15:57
#include <iostream>
using namespace std;

int main(void)
{
    cout << system("pause");
    return 0;
}
第一个应该是这么写的吧,刚刚差点给绕进去了,这句话的意思是输出“请按任意键继续”,system("pause")就是从程序里调用“pause”命令
#9
liudw22012-07-24 15:59
试试在第一个代码里cout<<后面加上分号,那也是不能执行的
#10
有容就大2012-07-24 22:27
回复 7楼 liudw2
这个解释的可能有点不对 呵呵。
#11
pangding2012-07-24 23:59
坐等 有容 公布答案。
#12
pangding2012-07-25 01:18
得闲查了一下标准:
2.7 Comments
1 The characters /* start a comment, which terminates with the characters */. These comments do not nest.
   The characters // start a comment, which terminates with the next new-line character. If there is a form-
   feed or a vertical-tab character in such a comment, only white-space characters shall appear between it and
   the new-line that terminates the comment; no diagnostic is required. [Note: The comment characters //,
   /*, and */ have no special meaning within a // comment and are treated just like other characters. Simi-
   larly, the comment characters // and /* have no special meaning within a /* comment. ]
我翻译了一下:
2.7 注释
1 字符组 /* 启始一个注释,该注释止于字符组 */。这类注释不得嵌套。字符组 // 启始一个注释,该注释止于换行符(newline, NL, '\n')。
   如果在这类注释中含有换页符(formfeed, FF, '\f')或垂向制表符(vertical-tab, VT, '\v'),则在它们与终止注释的换行符之间只允许出现
   空白字符;没有诊断要求。[注:注释字符 //, /* 和 */ 在 // 注释中没有任何特殊含意,一个 // 注释仅将它们视作普通字符。相仿,注释
   字符 // 和 /* 在 /* 注释中没有任何含意。]

#13
有容就大2012-07-25 11:03
呵呵 P版认真负责啊 是那样的呢
#14
hellovfp2012-07-25 11:29
又回来编程了?准备进驻C++区了?
#15
有容就大2012-07-25 11:37
回复 14楼 hellovfp
哈哈 有这个打算
#16
hellovfp2012-07-25 11:42
不会吧?真的?
那C++区会发大水的。。。。
冲走了一批又一批的版主。
#17
有容就大2012-07-25 11:45
回复 16楼 hellovfp
可能有点小小的涟漪吧.
#18
woshiluli32012-07-25 12:05
试了下,上面说的是/*"/***/"*/;缺少右引号"      
                  system("pause"); 的system前缺少分号;
/*"/***/这个应该是注释吧
#19
lz10919149992012-07-25 21:23
输出的是system("pause");的返回值。
#20
pangding2012-07-26 00:18
回复 17楼 有容就大
嘿,有容要是足够活跃,下次选举我一定投你一票。
#21
有容就大2012-07-26 11:42
回复 20楼 pangding
呵呵 努力向版主和大牛们学习,和朋友们共同进步,不敢乱想啊。
#22
young_he2012-08-12 09:46
liudw2的解释应该是对的吧     第二个程序这样就没问题了 cout << /*"/***/"*/";  就是在分号前面加一个引号!
1