简体   繁体   English

C++ 如何使用 .find_first_not_of()

[英]C++ how to use .find_first_not_of()

I am supposed to be checking to make sure my number is in the base.我应该检查以确保我的号码在基地。 ex: if the base was 10 only the first 10 characters from base value could be used (0-9).例如:如果基数为 10,则只能使用基值中的前 10 个字符 (0-9)。 When i try to run my code i keep getting this message "[Error] invalid conversion from 'std::basic_string::size_type {aka long long unsigned int}' to 'const char*' [-fpermissive]" can someone please help me?当我尝试运行我的代码时,我不断收到此消息“[错误] 从 'std::basic_string::size_type {aka long long unsigned int}' 到 'const char*' [-fpermissive] 的无效转换”有人可以帮忙吗我?

const string base_vals = "0123456789abcdefghijklmnopqrstuvwxyz";
string metadrome(string n, int base){
    string new_base_vals= base_vals.substr(0,base);
    string number=n;
    string q = number.find_first_not_of(new_base_vals)
    return q;
}

edit: this is not the full code just a small portion in which I'm having difficulty the input string n and int base are user entered values编辑:这不是完整的代码只是我遇到困难的一小部分输入字符串 n 和 int base 是用户输入的值

The return value of std::string::find_first_not_of() is a size_t . std::string::find_first_not_of()的返回值是size_t You need to change the call to您需要将呼叫更改为

size_t q = number.find_first_not_of(new_base_vals);

Don't forget to change the signature of metadrome() as well.不要忘记更改metadrome()的签名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM