Stroustrup 5.9,练习11 [英] Stroustrup 5.9, exercise 11
问题描述
没有编译时错误。在我输入输入并按下ENTER后,我发现
得到运行时错误。这是代码:
---------- PROGRAM --------------
/ * Stroustrup,5.9,运动
11
声明:
从输入中读取一系列单词。使用退出作为
字
终止输入。按照他们输入的
的顺序打印单词。不要打印一个单词两次。修改程序打印
单词打印前
他们。
* /
#include< iostream>
#include< string>
int main()
{
const std :: string EOI =" quit" ;; //结束
输入
char * user_input ="" ;;
const int max_input = 1000;
char * collect_input [max_input + 1];
for(int i = 0; user_input!= EOI || i< max_input; ++ i)
{
std :: cin> user_input;
collect_input [i] = user_input;
}
返回0;
}
-------------输出 - -----------
[arch @ voodo tc ++ pl] $ g ++ 5.9_ex-11.cpp
[arch @ voodo tc + + pl] $ ./a.out
喜欢
分段错误
[arch @ voodo tc ++ pl] $
g ++ 5.9_ex-11.cpp
[arch @ voodo tc ++ pl]
./ a.out
喜欢
分段错误
[arch @ voodo tc ++ pl]
there is no "compile-time error". after i enter input and hit ENTER i
get a run-time error. here is the code:
---------- PROGRAMME --------------
/* Stroustrup, 5.9, exercise
11
STATEMENT:
Read a sequence of words from the input. use "quit" as the
word
to terminate the input. Print the words in the order they
were
entered. don''t print a word twice.modify the programme to sort
the
words before printing
them.
*/
#include<iostream>
#include<string>
int main()
{
const std::string EOI = "quit"; // End Of
Input
char* user_input = "";
const int max_input = 1000;
char* collect_input[max_input + 1];
for(int i=0; user_input != EOI || i < max_input; ++i)
{
std::cin >user_input;
collect_input[i] = user_input;
}
return 0;
}
------------- OUTPUT -------------
[arch@voodo tc++pl]$ g++ 5.9_ex-11.cpp
[arch@voodo tc++pl]$ ./a.out
like
Segmentation fault
[arch@voodo tc++pl]$
g++ 5.9_ex-11.cpp
[arch@voodo tc++pl]
./a.out
like
Segmentation fault
[arch@voodo tc++pl]
这篇关于Stroustrup 5.9,练习11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!