C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
why get this error Posted by noora on 24 Jan 2006 at 7:52 AM
This message was edited by noora at 2006-1-24 7:56:41

Hi everyone

the code is
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);
				sum += atoi(last_digit) ;
                cout << sum << endl;            
            }

this program get retieve int value from a file, I take the dec convert it to binary using itoa after that take the last byte of the binary and assign it to last_digit then I would like to sum the last digit so I convert the string to int and did the sum sum += atoi(last_digit) ;
I would like to sum only the last digit of the binary number,
but it gives me this error
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.


dose anyone have an idea.

thank you in advance


Report
Re: why get this error Posted by HK_MP5KPDW on 24 Jan 2006 at 8:16 AM
: This message was edited by noora at 2006-1-24 7:56:41

: Hi everyone
:
: the code is
:
: 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);
: 				sum += atoi(last_digit) ;
:                 cout << sum << endl;            
:             }
: 

: this program get retieve int value from a file, I take the dec convert it to binary using itoa after that take the last byte of the binary and assign it to last_digit then I would like to sum the last digit so I convert the string to int and did the sum sum += atoi(last_digit) ;
: I would like to sum only the last digit of the binary number,
: but it gives me this error
:
: 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.
: 

:
: dose anyone have an idea.
:
: thank you in advance
:
:

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

sum += atoi(last_digit.c_str());


Note: It doesn't look like you've initialized the sum variable in the above code.

Report
Re: why get this error Posted by noora on 24 Jan 2006 at 10:13 AM
thank you so much for you help

: : This message was edited by noora at 2006-1-24 7:56:41

: : Hi everyone
: :
: : the code is
: :
: : 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);
: : 				sum += atoi(last_digit) ;
: :                 cout << sum << endl;            
: :             }
: : 

: : this program get retieve int value from a file, I take the dec convert it to binary using itoa after that take the last byte of the binary and assign it to last_digit then I would like to sum the last digit so I convert the string to int and did the sum sum += atoi(last_digit) ;
: : I would like to sum only the last digit of the binary number,
: : but it gives me this error
: :
: : 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.
: : 

: :
: : dose anyone have an idea.
: :
: : thank you in advance
: :
: :
:
: The atoi function expects a C-style (NULL Terminated) array of characters and not a C++ std::string object which you are attempting to pass. You need to use the string's c_str() member function to convert the data in the string object into something that the function can use:
:
:
sum += atoi(last_digit.c_str());
: 

:
: Note: It doesn't look like you've initialized the sum variable in the above code.
:

:

Report
check this please Posted by noora on 1 Feb 2006 at 1:25 PM
This message was edited by noora at 2006-2-2 5:12:22

This message was edited by noora at 2006-2-1 13:27:29

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.
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;
}


thank you

: : This message was edited by noora at 2006-1-24 7:56:41

: : Hi everyone
: :
: : the code is
: :
: : 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);
: : 				sum += atoi(last_digit) ;
: :                 cout << sum << endl;            
: :             }
: : 

: : this program get retieve int value from a file, I take the dec convert it to binary using itoa after that take the last byte of the binary and assign it to last_digit then I would like to sum the last digit so I convert the string to int and did the sum sum += atoi(last_digit) ;
: : I would like to sum only the last digit of the binary number,
: : but it gives me this error
: :
: : 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.
: : 

: :
: : dose anyone have an idea.
: :
: : thank you in advance
: :
: :
:
: The atoi function expects a C-style (NULL Terminated) array of characters and not a C++ std::string object which you are attempting to pass. You need to use the string's c_str() member function to convert the data in the string object into something that the function can use:
:
:
sum += atoi(last_digit.c_str());
: 

:
: Note: It doesn't look like you've initialized the sum variable in the above code.
:

:





Report
Re: check this please Posted by stober on 2 Feb 2006 at 6:26 AM
: 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.
Report
Re: check this please Posted by noora on 2 Feb 2006 at 6:57 AM
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.
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, 



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.
:

Report
Re: check this please Posted by stober on 2 Feb 2006 at 11:56 AM
This message was edited by stober at 2006-2-2 11:59:20

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.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.