为什么我的 C++ 程序在我接受字符串输入后立即终止?

时间:2021-02-11 05:35:09

标签: c++ string exception c++14 terminate

我正在尝试从用户“上午 11 点 59 分”处获取时间输入,但一旦我提供输入,它就会终止。

<块引用>

'p' 的输入格式为 11:59 AM,'s' 的输入格式为 10:00 AM 11:00 AM

user@user-VirtualBox:/media/sf_shared_folder$ make hello
cc     hello.c   -o hello
hello.c: In function ‘init_module’:
hello.c:11:4: warning: implicit declaration of function ‘printk’ [-Wimplicit-function-declaration]
   11 |    printk(KERN_INFO "Hello , user!\n");
      |    ^~~~~~
hello.c:11:11: error: ‘KERN_INFO’ undeclared (first use in this function)
   11 |    printk(KERN_INFO "Hello , user!\n");
      |           ^~~~~~~~~
hello.c:11:11: note: each undeclared identifier is reported only once for each function it appears in
hello.c:11:20: error: expected ‘)’ before string constant
   11 |    printk(KERN_INFO "Hello , user!\n");
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                    )
hello.c: In function ‘cleanup_module’:
hello.c:17:11: error: ‘KERN_INFO’ undeclared (first use in this function)
   17 |    printk(KERN_INFO "Goodbye , user!\n");
      |           ^~~~~~~~~
hello.c:17:20: error: expected ‘)’ before string constant
   17 |    printk(KERN_INFO "Goodbye , user!\n");
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                    )
hello.c: At top level:
hello.c:21:16: error: expected declaration specifiers or ‘...’ before string constant
   21 | MODULE_LICENSE("GPL");
      |                ^~~~~
hello.c:22:20: error: expected declaration specifiers or ‘...’ before string constant
   22 | MODULE_DESCRIPTION("My first cool kernel module");
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hello.c:23:15: error: expected declaration specifiers or ‘...’ before string constant
   23 | MODULE_AUTHOR("user");
      |               ^~~~~~~~~~~~~
make: *** [<builtin>: hello] Error 1

0 个答案:

没有答案