How to subtract string arrays?

This is a discussion on How to subtract string arrays? within the C++ Programming forums, part of the General Programming Boards category; I was wondering if someone could tell me how to subtract two string arrays. I use getline() that is why ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    37

    How to subtract string arrays?

    I was wondering if someone could tell me how to subtract two string arrays. I use getline() that is why the array is a string. It is in my main, but the below code is my function.
    Also the data inside the array is just numbers such as: 88 91 100 etc, Just want to subtract those numbers

    I Get the errors from these two lines of code.
    Code:
    HUFFMAN[i] = dataCASE1[i] - dataCASE1[i-16];
    Code:
    HUFFMAN[i] = dataCASE1[i] - dataCASE1[i-1];

    Code:
    void algor1(int sizeCASE1, int columnCASE1, string dataCASE1[]){    
        string HUFFMAN[256];
        ofstream outStream;
    
    
        outStream.open("outfile.txt");
    
    
        if(outStream.fail())
        {
            cout << "Output file opening failed.\n";
            exit(1);
        }
    
    
        HUFFMAN[0] = dataCASE1[0];
    
    
        for(int i = 1; i < sizeCASE1; i++)
        {
            if(i == columnCASE1)
            {
                HUFFMAN[i] = dataCASE1[i] - dataCASE1[i-16];
            }
            else
                HUFFMAN[i] = dataCASE1[i] - dataCASE1[i-1];
        }
    
    
        for(int j = 0; j < sizeCASE1; j++)
        {
            outStream << HUFFMAN[j];
        }
        outStream.close();
    }

    Thanks
    Last edited by geewhan; 06-29-2012 at 05:26 PM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,301
    You need to extract the numbers from the string in some suitable order, do the subtraction, and (if you need the results as a string) write the results back to the string in some manner.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    If you get errors, that's great; all you need to do now is post them.
    No sense keeping them to yourself, share 'em around.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-27-2011, 05:40 PM
  2. shift-and-subtract divider
    By tox0tes in forum C Programming
    Replies: 1
    Last Post: 01-17-2010, 12:22 AM
  3. Replies: 15
    Last Post: 01-24-2008, 08:40 PM
  4. Add, Subtract Calculator...
    By Crash1322 in forum C++ Programming
    Replies: 8
    Last Post: 12-14-2003, 10:38 PM
  5. How to add/subtract from array element...
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 05-01-2002, 10:04 PM

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