该计划的任何改进 [英] any improvements for this programme

查看:38
本文介绍了该计划的任何改进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/ * C ++ Primer 4 / e

*第3.2节 - 字符串标准库


*练习3.8

*声明

*编写程序从标准输入读取字符串,连接

所有这些*在一个字符串中,每个输入字符串由

分隔空格然后打印出来。 * /


#include< iostream>

#include< string>


int main()

{

std :: string input_string,final_string;


while(std :: cin> input_string)

if(final_string.empty())// without" if"我们将得到一个

的空白

final_string + = input_string; //在final_string的开头。

else

final_string = final_string +" " + input_string;


std :: cout<< final_string<< std :: endl;


返回0;

}

它工作正常

- http://arnuld.blogspot.com

/* C++ Primer 4/e
* section 3.2 - String Standard Library

* exercise 3.8
* STATEMENT
* write a programme to read strings from standard input, concatenate
all of them * in one string where each input string is seperated by
whitespace and then print it. */

#include <iostream>
#include <string>

int main()
{
std::string input_string, final_string;

while(std::cin >input_string)
if(final_string.empty()) // without "if" we will get a
whitespace
final_string += input_string; // at the beginning of final_string.
else
final_string = final_string + " " + input_string;

std::cout << final_string << std::endl;

return 0;
}
it works fine
-- http://arnuld.blogspot.com

推荐答案

arnuld写道:
arnuld wrote:

/ * C ++ Primer 4 / e

* section 3.2 - String Standard图书馆


*练习3.8

*语句

*编写程序从标准输入读取字符串,连接

所有这些*在一个字符串中,每个输入字符串由

空格分隔,然后打印出来。 * /


#include< iostream>

#include< string>


int main()

{

std :: string input_string,final_string;


while(std :: cin> input_string)

if(final_string.empty())// without" if"我们将得到一个

的空白

final_string + = input_string; //在final_string的开头。

else

final_string = final_string +" " + input_string;


std :: cout<< final_string<< std :: endl;


返回0;

}
/* C++ Primer 4/e
* section 3.2 - String Standard Library

* exercise 3.8
* STATEMENT
* write a programme to read strings from standard input, concatenate
all of them * in one string where each input string is seperated by
whitespace and then print it. */

#include <iostream>
#include <string>

int main()
{
std::string input_string, final_string;

while(std::cin >input_string)
if(final_string.empty()) // without "if" we will get a
whitespace
final_string += input_string; // at the beginning of final_string.
else
final_string = final_string + " " + input_string;

std::cout << final_string << std::endl;

return 0;
}



将表达式放在括号中,它使代码更清晰,更容易

维护。


尽量避免使用包装的行尾注释发布代码,C风格

评论对Usenet更安全。


-

Ian Collins。

Put your expressions in braces, it makes the code clearer and easier to
maintain.

Try and avoid posting code with end of line comments that wrap, C style
comments are safer for Usenet.

--
Ian Collins.


在2007年7月18日星期三20:44:31 +1200,Ian Collins写道:
On Wed, 18 Jul 2007 20:44:31 +1200, Ian Collins wrote:

将表达式放在括号中,它使代码更清晰,更容易

维持。
Put your expressions in braces, it makes the code clearer and easier to
maintain.



ok ..完成

ok.. done


尝试并避免使用包装的行尾注释发布代码,
Try and avoid posting code with end of line comments that wrap,



i donot得到它。什么是包装的行尾注释 ?

i donot get it. what are "end of line comments that wrap" ?


C风格注释对Usenet更安全。
C style comments are safer for Usenet.



你说/ * * /对于USENET更安全但对C ++程序员更安全吗?


-

- http://arnuld.blogspot.com

ok you said /* */ are safer for USENET but not for C++ programmer ??

--
-- http://arnuld.blogspot.com


arnuld写道:
arnuld wrote:

> 7月18日星期三2007 20:44:31 +1200,Ian Collins写道:
>On Wed, 18 Jul 2007 20:44:31 +1200, Ian Collins wrote:


>将表达式放在大括号中,它使代码更清晰,更容易<保持。
>Put your expressions in braces, it makes the code clearer and easier to
maintain.



ok ..完成


ok.. done


>尝试并避免发布包含行尾注释的代码,
>Try and avoid posting code with end of line comments that wrap,



i donot得到它。什么是包装的行尾注释 ?


i donot get it. what are "end of line comments that wrap" ?



看看你的代码发布后你的代码是如何出现的,你的评论是在

之后如果包裹到下一行,那么如果有的话试图复制并通过

代码进行编译,他们必须先修复代码。

Look at how your code appeared after you posted it, your comment after
the if wrapped to the next line, so if anyone tried to copy and past the
code to compile it, they would have to fix up the code first.


> C风格评论对Usenet更安全。
>C style comments are safer for Usenet.



你说/ * * /对于USENET更安全但对C ++程序员更安全吗?


ok you said /* */ are safer for USENET but not for C++ programmer ??



if(final_string.empty())// without" if"我们将得到一个

的空白


不会编译


if(final_string.empty()) / *没有如果我们将获得一个

的空白* /


将。


-

Ian Collins。

if(final_string.empty()) // without "if" we will get a
whitespace

won''t compile

if(final_string.empty()) /* without "if" we will get a
whitespace */

will.

--
Ian Collins.


这篇关于该计划的任何改进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆