dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: error: expected primary-expression before string ‘teee’

  1. #1
    Join Date
    Aug 2018
    Posts
    5

    error: expected primary-expression before string ‘teee’

    Hello coding community,
    The code below is a variation on the run-length encoding but adapted for my hex string. The code is supposed to take the string and put a space between every two characters eg "3030" becomes "30 30" and puts the output of that into bytes vector and from that into the array. Now, it will place an array element into the temphexholder array and check if the next array element of databytes is the same as the element in temphexholder it will increment counter if not it will append counter and databytes to runlengthengthcoding string. So the result is eg. : original string: "303030304040" becomes "30044002". However when I try to use the function it gives me the error in the title
    Code:
    string integerrunlengthencoding(string hextext) {
        //string hextext = "";
        int counter,a;
        unsigned char temphexholder[1];
        cout << hextext ; 
        int length = hextext.size();
            string output = "";
        string runlengthengthcoding = "";
     
            //for each block of 2 characters
            for(int i =0 ; i< length; i=i+2)
            {
            //copy 2 characters and a space to the output
            output += hextext.substr(i, 2) + " ";
     
            }
        std::istringstream hex_chars_stream(output);
        std::vector<unsigned char> bytes;
        unsigned int c;
        unsigned char databytes[52]; // 52 data bytes
        while (hex_chars_stream >> std::hex >> c)
        {
                bytes.push_back(c);
            
        }
        for(int q=0;q<52;q++){ 
            databytes[q] = bytes[q]; 
            
        }    
        for(int w=0;w<52;w++){
            
            if(temphexholder[0] == databytes[w]){
                counter++;        
            }
            if(temphexholder[0] != databytes[w]){
                runlengthengthcoding += databytes[w] + counter;    
                counter = 0;
                temphexholder[0] = databytes[w];
            }
            
        }
        return runlengthengthcoding;
    }
    
    int main (){
    string teee = "303040505050efef30454540404040405050502021212123232345562929293445232334458939414123232323232323456789";
        
        cout << teee;    
        cout  << "The compressed string becomes: " << integerrunlengthencoding(string teee);
    }   // why is this not working

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,354

    Re: error: expected primary-expression before string ‘teee’

    Code:
    cout  << "The compressed string becomes: " << integerrunlengthencoding(string teee);
    You don't specify string here as you are calling the function - not defining it. So

    Code:
    cout  << "The compressed string becomes: " << integerrunlengthencoding(teee);
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.6)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)