关于C++输入函数类型的汇总(如get;gets;getline等)

首先明确cin的特点:①遇到空格,换行符等空白字符作为一个数据的结束。

                                  ②输入完数据按回车键即执行。

                                  ③输入类型取决于变量被定义的类型(int,double,char,string等)

一、cin.get函数对应char

(1)输入常数

 cin.get()提取一个字符

getchar函数功能相同

(2)输入并赋给一个参数

cin.get(x)提取一个字符并赋给变量x

(3)输入并赋给字符数组

cin.get(x,n,终止字符)读取n-1个字符赋给字符串数组(x应为数组名)

二、cin.getline函数对应char

cin.getline(x,n,终止字符)读取一行字符中的前n-1个赋给x

三、gets函数对应char

gets(x)读取一行字符赋给x字符数组

四、getline函数对应string

getline(cin,x,终止字符)终止字符可省略,默认'\n',读取一行字符赋给x

不难看出,函数各具特点,gets简单粗暴,没什么要求,但由于其安全性C11委员会已将其废除,能不用尽量不用;cin.根据类型不同语法不同;cin.getline要求多;getline特殊对应string类型。

当我们需要考虑输入时,大多是输入量不明确,比如输入一行输入一个句子,中间有空格。而在处理输入时常常有需要长度,所以给出一种常用形式:

char str[N];
int i=0;
while((str[i]=getchar())!='\n'){   //存在str字符数组中
    i++;                           //最终数组长度为i(从0开始)
}

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Frida-Gum is a powerful instrumentation framework for dynamic binary analysis and reverse engineering. It provides a high-level API for writing custom code to interact with native code running on different platforms. To use Gum to find a C++ class method function using C++ code, you can start by loading your target binary into memory using the `gum_process_attach()` function. Once attached, you can use `gum_module_find_export_by_name()` function to find the address of the C++ class method function inside the target binary. Here is an example code snippet that demonstrates how to use Gum to find a C++ class method function: ```c++ #include <gum/gum.h> class MyClass { public: void myMethod(int arg1, int arg2) { // implementation of myMethod } }; int main() { gum_init_embedded(); GumAddress myMethodAddress = 0; GumAddress targetAddress = gum_module_find_base_address("mybinary"); if (targetAddress != 0) { GumExportDetails exportDetails; if (gum_module_find_export_by_name("mybinary", "_ZN7MyClass8myMethodEii", &exportDetails)) { myMethodAddress = exportDetails.address; } } // myMethodAddress now contains the address of MyClass::myMethod() gum_deinit_embedded(); return 0; } ``` In this example, we defined a simple C++ class `MyClass` with a method `myMethod()`. We then attached to the target binary using `gum_process_attach()`, and used `gum_module_find_export_by_name()` to find the address of the `MyClass::myMethod()` function inside the target binary. The function signature `_ZN7MyClass8myMethodEii` corresponds to the mangled name of the `MyClass::myMethod()` function in C++. Note that this is just a basic example, and you will need to adapt the code to your specific use case. Also, keep in mind that using Gum to interact with native code requires a good understanding of the target binary and its environment.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值