小编Aer*_*lSP的帖子

在g ++ 4.7.2中缺少std :: stoi?

当我尝试使用std :: stoi并尝试编译它时,我收到错误消息"stoi不是std的成员".我从命令行使用g ++ 4.7.2所以它不能是IDE错误,我按顺序包含所有我的包含,而g ++ 4.7.2默认使用c ++ 11.如果有帮助,我的操作系统是Ubuntu 12.10.有没有配置的东西?

#include <iostream>
#include <string>

using namespace std;

int main(){
  string theAnswer = "42";
  int ans = std::stoi(theAnswer, 0, 10);

  cout << "The answer to everything is " << ans << endl;
}
Run Code Online (Sandbox Code Playgroud)

不会编译.但它没有任何问题.

c++ compiler-errors g++ std c++-standard-library

11
推荐指数
1
解决办法
2万
查看次数

如何从声明性宏返回新字符串?

所以我在这里,和 Rustlings 一起用卡车运输,直到我在测试 4 中遭到猛烈攻击。

它要求我编写一个满足以下代码的宏:

fn main() {
    if my_macro!("world!") != "Hello world!" {
        panic!("Oh no! Wrong output!");
    }
}
Run Code Online (Sandbox Code Playgroud)

所以,我写了这个:

macro_rules! my_macro {
    ($val:expr) => {
        println!("Hello {}", $val);
    }
}
Run Code Online (Sandbox Code Playgroud)

Rustlings 吐出了这一点:

fn main() {
    if my_macro!("world!") != "Hello world!" {
        panic!("Oh no! Wrong output!");
    }
}
Run Code Online (Sandbox Code Playgroud)

哪个,你知道。我明白了。我明白问题是什么,但我不明白如何编写一个满足代码的宏。我可以更改正在测试的代码,但这不是测试想要我做的。我只是写一个宏。我很困惑。我也不明白将宏封装在模块中有何帮助,但测试表明这是对模块和宏的测试。

string rust rust-macros rust-decl-macros

4
推荐指数
1
解决办法
1452
查看次数