String Swapping

This is a discussion on String Swapping within the C++ Programming forums, part of the General Programming Boards category; This is the code I have so far: #include <fstream> #include <iostream> #include <cstdlib> #include <string> using namespace std; string ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    6

    String Swapping

    This is the code I have so far:


    #include <fstream>
    #include <iostream>
    #include <cstdlib>
    #include <string>

    using namespace std;
    string date;

    //The following are the functions for the different htm's



    /////////////////////////////////////////////////////
    //Adds New Date to cwchartlist function
    /////////////////////////////////////////////////////
    void cwchartlist(ifstream& in_stream, ofstream& out_stream)
    {
    char next;

    in_stream.get(next);
    while (! in_stream.eof())
    {
    if (next == '*')
    out_stream << " ";
    else
    if (next == '@')
    { out_stream << "Amperage " << date << "* </p>";
    out_stream << endl;
    out_stream << "@";
    }
    else
    if (next == '$')
    { out_stream << "kVAR/kVA " << date << "* </p>";
    out_stream << endl;
    out_stream << "$";
    }


    else
    out_stream << next;

    in_stream.get(next);
    }


    }



    //////////////////////////////////////////////////////
    //////////////////////////////////////////////////////

    int main()
    {
    cout << "Enter Date: ";
    cin >> date;
    //////////////////////////////////////////////////////
    // Adds New Date to cwchartlist
    /////////////////////////////////////////////////////
    ifstream fincwchartlist;
    ofstream foutnewcwchartlist;

    cout << "Begin editing cwchartlist.\n";

    fincwchartlist.open("cwchartlist.htm");
    if (fincwchartlist.fail())
    {
    cout << "cwchartlist opening failed.\n";
    exit(1);
    }

    foutnewcwchartlist.open("newcwchartlist.htm");
    if (foutnewcwchartlist.fail())
    {
    cout << "newcwchartlist opening failed.\n";
    exit(1);
    }


    cwchartlist(fincwchartlist, foutnewcwchartlist);

    fincwchartlist.close();
    foutnewcwchartlist.close();

    cout << "End of editing newcwchartlist.\n";


    ///////////////////////////////////////////////////////

    return 0;
    }

    Okay, this code works fine, but what I want to do is instead of looking for a symbol like "@" I want to search for "ampdate" or something similiar and replace it with the date "02-19-02.

    Or is what i'm trying to do impossible?

    Thank you

    Bryan
    Last edited by RustGod; 02-20-2002 at 05:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. += operator
    By BKurosawa in forum C++ Programming
    Replies: 8
    Last Post: 08-05-2007, 03:58 AM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM

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