atoi error need help - please:(

This is a discussion on atoi error need help - please:( within the C++ Programming forums, part of the General Programming Boards category; error C2664: 'atoi' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *' No user-defined-conversion ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    9

    Unhappy atoi error need help - please:(

    error C2664: 'atoi' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    Error executing cl.exe.
    -----------------------------------------------------------------------------------
    #include <fstream>
    #include <iomanip>
    #include <iostream>
    #include <stdlib.h>
    #include <string>
    #include <stdio.h>
    using namespace std;
    int main ()
    {
    ifstream Member_Span;
    ofstream Member_Out;
    string line;
    string MemNum, DocAreaCode, TransDate, Name;
    string TD;
    int TDtoi;
    int TransDateSelect;
    cout << "Please enter a 1 or 2 for the transaction date. ";
    cin >> TransDateSelect;
    Member_Span.open ("Member_Span.txt");
    if (Member_Span.fail ())
    {
    cout << "Cannot Open File: " << endl;
    return EXIT_FAILURE;
    }
    while (Member_Span.good ())
    {
    getline(Member_Span, line);
    MemNum=line.substr(0,3);
    DocAreaCode=line.substr(3,2);
    TransDate=line.substr(5,1);
    Name=line.substr(6,10);
    TD = TransDate;
    TDtoi = atoi( TD );
    if (TDtoi == TransDateSelect)
    {
    cout << MemNum << " " << DocAreaCode << " " << TransDate << " " << Name << endl;
    }
    }
    Member_Span.close ();
    return EXIT_SUCCESS;
    }

    appreciate any help

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    The string you are atoi() supplying with should be of type char *. I guess you're variable TD is not of that type.

  3. #3
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Try -

    TDtoi = atoi( TD.c_str() );

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    9
    Thanks, my prof said the same thing. It worked perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble with atoi
    By NewbGuy in forum C Programming
    Replies: 2
    Last Post: 05-22-2009, 11:55 PM
  2. help with this
    By tyrantil in forum C Programming
    Replies: 18
    Last Post: 01-30-2005, 03:53 PM
  3. Problem with atoi in C
    By garagebrian in forum C Programming
    Replies: 5
    Last Post: 08-24-2004, 01:59 PM
  4. string to int conversion not using atoi()
    By linucksrox in forum C Programming
    Replies: 2
    Last Post: 05-19-2004, 12:17 AM
  5. how to use atoi!!!
    By moon in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2002, 08:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21