2013-12-23 155 views
-1

我弄不清楚我的编译器不喜欢什么。我保证我将使用StackOverflow作为最后的手段,并且我正在尽我所能自行解决问题。“str2Int(std :: basic_string <char,std :: char_traits <char>,std :: allocator <char>> const&)”,引用自:

“str2Int(性病:: basic_string的,性病::分配器>常量&)”,从引用:在main.o中

#include <iostream> 
#include <string> 

bool valid_equation(const std::string&); 
int str2Int(const std::string&); 

int main (int argc, char* const argv[]) { 

    std::cout << str2Int("0034"); 

    //std::cout << valid_equation("5*2+3"); 

    return 0; 
} 

/* 
bool valid_equation(const std::string& eq) { 
    std::string::const_iterator it = eq.begin(); 



} 
*/ 

int str2int(const std::string& str) { 

    // Still need to add error checking 

    int i = 0; 
    std::string::const_iterator it = str.begin(); 
    while (it != str.end()) { 
     i *= 10; 
     i += *it++ - '0'; 
    } 

    return i; 
} 
+0

如果你正在使用C++ 11,那么我会强烈推荐使用库函数来执行这个'std :: stoi(str)'而不是自己滚动。 – shuttle87

+2

通过删除这些错字相关的问题,我们可以真正使用你的帮助![活动清理堆栈溢出](http://meta.stackexchange.com/q/167342)!你可以通过在这个问题上进行近距离投票来介入一点吗? – Johnsyweb

回答

5

使用一致的大小写 _main。 str2Intstr2int不一样。

+0

呃......对不起。不知道我怎么没有看到。 – user2967799

+1

@ user2967799,不需要道歉,我们偶尔也会犯这样的错误。如果这解决了你的问题,请接受这个答案。 – shuttle87

+1

人们问我如何快速发现错误。我回答说我有很多练习做我自己的。 :-)顺便说一句,@ shuttle87,在问题被选为答案之前有15分钟的延迟。 –

相关问题