0
我有這些字符串:如何將char * string =「2001-02-03」翻譯爲整數格式?
const char * date = "2001-02-03";
const char * id = "987654/3210";
我需要非常快的轉換爲整數或可能長整型(用於ID)。我需要翻譯比較(數字strcmp()是慢)。我只有這個庫:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
實施例: 常量字符*日期= 「2001年2月3日」; - > int int_date = 20010203; const char * id =「987654/3210」; - > long long_id =;
怎麼辦?
提示:轉換爲int + INT比較(可忽略不計)是不太可能比字符串比較更快。如果多次**進行比較**,您只能從轉換中受益。 –