why get this error - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

why get this error

nooranoora Posts: 21Member
[b][red]This message was edited by noora at 2006-1-24 7:56:41[/red][/b][hr]
Hi everyone

the code is
[code]
int ats_array[] = {4};
const int ats_SIZE = sizeof ats_array / sizeof *ats_array;
string binary, last_digit;
unsigned long bit_num[ats_SIZE] ;
char buff[20];
int dec, sum;

for(int colm = 0; colm < ats_SIZE; colm++)
{
dec = GetintValue(ats_array[colm],line;
std::istringstream iss ( std::bitset ( dec ).to_string() );
iss>> bit_num[colm];
binary = itoa(bit_num[colm],buff,10);
last_digit= binary.substr(7,1);
[red] sum += atoi(last_digit) ;[/red]
cout << sum << endl;
}
[/code]
this program get retieve int value from a file, I take the[blue] dec [/blue]convert it to binary using [green]itoa[/green] after that take the last byte of the [blue]binary[/blue] and assign it to [blue]last_digit [/blue] then I would like to sum the last digit so I convert the string to int and did the sum [red] sum += atoi(last_digit) ;[/red]
I would like to sum only the last digit of the binary number,
but it gives me this error
[code]
error C2664: 'atoi' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
[/code]

dose anyone have an idea.

thank you in advance


Comments

  • HK_MP5KPDWHK_MP5KPDW Posts: 770Member ✭✭✭
    : [b][red]This message was edited by noora at 2006-1-24 7:56:41[/red][/b][hr]
    : Hi everyone
    :
    : the code is
    : [code]
    : int ats_array[] = {4};
    : const int ats_SIZE = sizeof ats_array / sizeof *ats_array;
    : string binary, last_digit;
    : unsigned long bit_num[ats_SIZE] ;
    : char buff[20];
    : int dec, sum;
    :
    : for(int colm = 0; colm < ats_SIZE; colm++)
    : {
    : dec = GetintValue(ats_array[colm],line;
    : std::istringstream iss ( std::bitset ( dec ).to_string() );
    : iss>> bit_num[colm];
    : binary = itoa(bit_num[colm],buff,10);
    : last_digit= binary.substr(7,1);
    : [red] sum += atoi(last_digit) ;[/red]
    : cout << sum << endl;
    : }
    : [/code]
    : this program get retieve int value from a file, I take the[blue] dec [/blue]convert it to binary using [green]itoa[/green] after that take the last byte of the [blue]binary[/blue] and assign it to [blue]last_digit [/blue] then I would like to sum the last digit so I convert the string to int and did the sum [red] sum += atoi(last_digit) ;[/red]
    : I would like to sum only the last digit of the binary number,
    : but it gives me this error
    : [code]
    : error C2664: 'atoi' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator >' to 'const char *'
    : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    : Error executing cl.exe.
    : [/code]
    :
    : dose anyone have an idea.
    :
    : thank you in advance
    :
    :

    [blue]The [italic]atoi[/italic] function expects a C-style (NULL Terminated) array of characters and not a C++ [italic]std::string[/italic] object which you are attempting to pass. You need to use the [italic]string[/italic]'s [italic]c_str()[/italic] member function to convert the data in the [italic]string[/italic] object into something that the function can use:

    [code]sum += atoi(last_digit[red].c_str()[/red]);
    [/code]

    Note: It doesn't look like you've initialized the [italic]sum[/italic] variable in the above code.
    [/blue]
  • nooranoora Posts: 21Member
    thank you so much for you help

    : : [b][red]This message was edited by noora at 2006-1-24 7:56:41[/red][/b][hr]
    : : Hi everyone
    : :
    : : the code is
    : : [code]
    : : int ats_array[] = {4};
    : : const int ats_SIZE = sizeof ats_array / sizeof *ats_array;
    : : string binary, last_digit;
    : : unsigned long bit_num[ats_SIZE] ;
    : : char buff[20];
    : : int dec, sum;
    : :
    : : for(int colm = 0; colm < ats_SIZE; colm++)
    : : {
    : : dec = GetintValue(ats_array[colm],line;
    : : std::istringstream iss ( std::bitset ( dec ).to_string() );
    : : iss>> bit_num[colm];
    : : binary = itoa(bit_num[colm],buff,10);
    : : last_digit= binary.substr(7,1);
    : : [red] sum += atoi(last_digit) ;[/red]
    : : cout << sum << endl;
    : : }
    : : [/code]
    : : this program get retieve int value from a file, I take the[blue] dec [/blue]convert it to binary using [green]itoa[/green] after that take the last byte of the [blue]binary[/blue] and assign it to [blue]last_digit [/blue] then I would like to sum the last digit so I convert the string to int and did the sum [red] sum += atoi(last_digit) ;[/red]
    : : I would like to sum only the last digit of the binary number,
    : : but it gives me this error
    : : [code]
    : : error C2664: 'atoi' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator >' to 'const char *'
    : : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    : : Error executing cl.exe.
    : : [/code]
    : :
    : : dose anyone have an idea.
    : :
    : : thank you in advance
    : :
    : :
    :
    : [blue]The [italic]atoi[/italic] function expects a C-style (NULL Terminated) array of characters and not a C++ [italic]std::string[/italic] object which you are attempting to pass. You need to use the [italic]string[/italic]'s [italic]c_str()[/italic] member function to convert the data in the [italic]string[/italic] object into something that the function can use:
    :
    : [code]sum += atoi(last_digit[red].c_str()[/red]);
    : [/code]
    :
    : Note: It doesn't look like you've initialized the [italic]sum[/italic] variable in the above code.
    : [/blue]
    :

  • nooranoora Posts: 21Member
    [b][red]This message was edited by noora at 2006-2-2 5:12:22[/red][/b][hr]
    [b][red]This message was edited by noora at 2006-2-1 13:27:29[/red][/b][hr]
    Hi I have small problem with this code, it suppose to get me the dd/mm/yyyy , but it only giving me dd, I would to have the full date from the csv file. any suggession would help me to solve this problem.
    [code]
    float GetValue(int column,string line)
    {
    stringstream sstr(line);
    string temp;

    for( int i = 0; i < column; ++i )
    getline(sstr,temp,',');

    return atof(temp.c_str());
    }


    int main()
    {
    ifstream input_file("Log_05.csv");
    string line;
    int count;
    int array[]={1};
    const int SIZE = sizeof array / sizeof *array;
    float date[ SIZE ] = {0.0}, value;

    if ( input_file.fail ())
    {
    cout << "Error opening file.";
    }
    else
    {
    for(int i = 0; i < 7; i++) // Scan the first 7 lines, which is not required
    getline(input_file, line);
    count = 8; // We are in the eighth line
    while(count <= 1447) // We have to add until 1447 lines..
    {
    getline(input_file,line);
    // number of elements in the above array
    for(int colm = 0; colm < SIZE; colm++)
    {
    value = GetValue(array[colm],line);
    }

    count++; // Increment the count, to go to the next line

    }
    count -= 8;


    for(i = 0; i < SIZE; i++)
    {

    cout << endl << "The date of all values of column " << array[i]
    << " is : "<<value <<endl;
    }

    }

    return 0;
    }
    [/code]

    thank you

    : : [b][red]This message was edited by noora at 2006-1-24 7:56:41[/red][/b][hr]
    : : Hi everyone
    : :
    : : the code is
    : : [code]
    : : int ats_array[] = {4};
    : : const int ats_SIZE = sizeof ats_array / sizeof *ats_array;
    : : string binary, last_digit;
    : : unsigned long bit_num[ats_SIZE] ;
    : : char buff[20];
    : : int dec, sum;
    : :
    : : for(int colm = 0; colm < ats_SIZE; colm++)
    : : {
    : : dec = GetintValue(ats_array[colm],line;
    : : std::istringstream iss ( std::bitset<sizeof dec * CHAR_BIT> ( dec ).to_string() );
    : : iss>> bit_num[colm];
    : : binary = itoa(bit_num[colm],buff,10);
    : : last_digit= binary.substr(7,1);
    : : [red] sum += atoi(last_digit) ;[/red]
    : : cout << sum << endl;
    : : }
    : : [/code]
    : : this program get retieve int value from a file, I take the[blue] dec [/blue]convert it to binary using [green]itoa[/green] after that take the last byte of the [blue]binary[/blue] and assign it to [blue]last_digit [/blue] then I would like to sum the last digit so I convert the string to int and did the sum [red] sum += atoi(last_digit) ;[/red]
    : : I would like to sum only the last digit of the binary number,
    : : but it gives me this error
    : : [code]
    : : error C2664: 'atoi' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator >' to 'const char *'
    : : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    : : Error executing cl.exe.
    : : [/code]
    : :
    : : dose anyone have an idea.
    : :
    : : thank you in advance
    : :
    : :
    :
    : [blue]The [italic]atoi[/italic] function expects a C-style (NULL Terminated) array of characters and not a C++ [italic]std::string[/italic] object which you are attempting to pass. You need to use the [italic]string[/italic]'s [italic]c_str()[/italic] member function to convert the data in the [italic]string[/italic] object into something that the function can use:
    :
    : [code]sum += atoi(last_digit[red].c_str()[/red]);
    : [/code]
    :
    : Note: It doesn't look like you've initialized the [italic]sum[/italic] variable in the above code.
    : [/blue]
    :





  • stoberstober Posts: 9,765Member ✭✭✭
    : Hi I have small problem with this code, it suppose to get me the dd/mm/yyyy , but it only giving me dd, I would to have the full date from the csv file. any suggession would help me to solve this problem.

    please post a line from that .csv file so we can see what it looks like.
  • nooranoora Posts: 21Member
    Hi Stober
    I will paste only one line where the date is in the first column in the csv file and I would like to get that date only once, because it will repeated till the end of the file with the same date.by the way the first 7 rows in my original file are not require thats why I started from the 8th row. can you help in get the date value from that file and many thanks for your reply.
    [code]
    10/10/2004,00:00:45,190,0,13.94,345.28,200,18.46,32,3,47,6, ,127,228,226,228,344,128,64,64,9,6,5,50,50,50,34,34,34,6,6,6,0, ,63,228,226,228,344,66,66,66,11,7,7,50,50,50,34,36,35,6,6,6,0, ,49.41,0,0.06,32.87,0,63,6,4,0, ,49.67,0,0.06,28.95,0,63,6,4,0, ,49.67,0,-0.3,30.91,0,63,6,4,0, ,49.67,0,-0.3,32.87,0,63,6,4,0, ,49.67,0,-0.3,30.91,0,63,6,4,0, ,49.67,0,-0.3,32.87,0,63,6,4,0, ,49.94,0,0.06,30.91,0,63,6,4,0, ,49.41,0,-0.3,30.91,0,63,6,4,0, ,49.67,0,-0.3,32.87,0,63,6,4,0, ,49.41,0,-0.3,32.87,0,63,6,4,0, ,49.67,0,0.06,30.91,0,63,6,4,0, ,49.67,0,-0.3,36.79,0,63,6,4,0, ,49.41,0,-0.3,34.83,0,63,6,4,0, ,49.67,0,0.06,30.91,0,63,6,4,0,
    [/code]


    thanks again

    : : Hi I have small problem with this code, it suppose to get me the dd/mm/yyyy , but it only giving me dd, I would to have the full date from the csv file. any suggession would help me to solve this problem.
    :
    : please post a line from that .csv file so we can see what it looks like.
    :

  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2006-2-2 11:59:20[/red][/b][hr]
    For column = 1, GetValue() retrieves the entire date string, such as "10/10/2004". What format do you want the date in? time_t like returned by time() function? struct tm? type DATE that appears in many databases?

    If you want just the string, then write an overloaded GetValue() function that returns the string instead of a float.


Sign In or Register to comment.