溫馨提示×

c++中string轉int怎么實現

c++
小億
106
2024-03-15 17:26:54
欄目: 編程語言

在C++中,可以使用std::stoi函數將字符串轉換為整數。示例如下:

#include <iostream>
#include <string>

int main() {
    std::string str = "123";
    int num = std::stoi(str);
    
    std::cout << num << std::endl;

    return 0;
}

在上面的示例中,std::stoi函數將字符串"123"轉換為整數123,并將其存儲在變量num中。然后可以將num打印出來。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女