464,386 Members | 1,165 Online
Need help? Post your question and get tips & solutions from a community of 464,386 IT Pros & Developers. It's quick & easy.

# convert string in to integer

 P: 6 Expand|Select|Wrap|Line Numbers struct time { int t;     int h,m,s;     };   int main() {     time t;     int totalsecond;     char A[10],B[10];     cout<<"Enter the time Format [12:59:59] = ";     cin.getline(A,10);     int i=0,j=0;     while(A[i]!=':')     {         B[j]=A[i];         i++;         j++;     }     t.h=atoi(B);     i++;     j=0;     while(A[i]!=':')     {         B[j]=A[i];         i++;         j++;     }     t.m=atoi(B);     i++;     j=0;     while(A[i]!='\0')     {         B[j]=A[i];         i++;         j++;     }     t.s=atoi(B);       totalsecond=(t.h*3600)+(t.m*60)+t.s;     cout<<"\n\nTotal Seconds are = "<
6 Replies

 Expert Mod 5K+ P: 9,197 What error are you getting? Sep 26 '13 #2

 P: 6 i am getting error at line no 8. t undeclared first use this function etc Sep 26 '13 #3

 Expert Mod 5K+ P: 9,197 Before you said it was line 12. Do you mean line 8 on your first post or line 12? If it turns out to be line 12 have you included ? Sep 26 '13 #4

 P: 6 yeah, i included it was on line 12 Sep 27 '13 #5

 P: 10 Try Expand|Select|Wrap|Line Numbers std::cin.getline   Sep 27 '13 #6

 P: 55 Try This Code Expand|Select|Wrap|Line Numbers #include  #include    int main() {       std::string s = "10";       try     {         int i = std::stoi(s);         std::cout << i << '\n';     }     catch (std::invalid_argument const &e)     {         std::cout << "Bad input: std::invalid_argument thrown" << '\n';     }     catch (std::out_of_range const &e)     {         std::cout << "Integer overflow: std::out_of_range thrown" << '\n';     }       return 0; } 3 Weeks Ago #7