Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:47:54+00:00 2026-06-15T12:47:54+00:00

See update below! My code (now I included more): while(getline(checkTasks, workingString)){ countTheDays = 0;

  • 0

See update below!

My code (now I included more):

while(getline(checkTasks, workingString)){
            countTheDays = 0;
            // Captures a clean copy of the line in tasks.dat in it's entirety, stores in workingString.
            char nlcheck;
            checkTasks.get(nlcheck);
            if(nlcheck == '\n'){
            }
            else{
                checkTasks.unget();
                //getline(checkTasks, workingString);
                // Breaks that line up into more usable pieces of information.
                getline(check2,tName, '\t');
                getline(check2,tDate, '\t');
                getline(check2,trDate, '\t');
                getline(check2,tComplete, '\n');
                // Converts the string form of these pieces into usable integers.
                stringstream(tDate.substr(0,tDate.find_first_of('/'))) >> year;
                stringstream(tDate.substr(tDate.find_first_of('/')+1,tDate.find_last_of('/'))) >> month;
                stringstream(tDate.substr(tDate.find_last_of('/')+1,tDate.length()-1)) >> day;
                stringstream(tComplete) >> checkComplete;
                stringstream(trDate) >> checkReminder;              

                // Adds the number of days until your task is due!
                if(year != date[0]){
                    for(int i = date[1]; i <= 12; i++){
                        countTheDays += System::DateTime::DaysInMonth(date[0], i);                      
                    }
                    countTheDays-= date[2];
                    for (int i = 1; i<= month; i++){
                        countTheDays +=System::DateTime::DaysInMonth(year, i);
                    }
                    countTheDays -= (System::DateTime::DaysInMonth(year, month) - day);
                }
                else if(month != date[1]){
                    for(int i = date[1]; i <= month; i++){
                        countTheDays += System::DateTime::DaysInMonth(date[0], i);
                    }
                    countTheDays -= (date[2]);
                    countTheDays -= (System::DateTime::DaysInMonth(year, month) - day);
                }
                else{
                    countTheDays+= System::DateTime::DaysInMonth(date[0], month);
                    countTheDays -= (System::DateTime::DaysInMonth(year, month) - day);
                    countTheDays -= date[2];                    
                }

                // If the task is nearing it's due date (the time frame specified to be notified) it'll notify user. 
                // Only coded to work if the task is due in the current or following months.
                if(countTheDays <= checkReminder){
                    if( countTheDays < 0){
                        cout << endl << endl << tName << " is past due!" << endl;
                        cout << "Should I keep reminding you about this task? Enter Y or N. ";
                        cin >> continueToRemind;
                    }
                    else{
                        cout << endl << endl << tName << " is due in " <<countTheDays << " days! Don't forget!" << endl;
                        cout << "Should I keep reminding you about this task? Enter Y or N. ";
                        cin >> continueToRemind;
                        }

                    // If user doesn't want to be reminded, begins process of converting that line in the file to usable info
                    // and 'overwriting' the old file by creating a new one, deleting the old one, and renaming the new one.
                    if(continueToRemind == "n" || continueToRemind == "N"){
                        fileModified = true;
                        string line;
                    /*  vector<string> lines;
                        while(getline(tasksClone, line)){
                            lines.push_back(line);
                        }
                        lines.erase(remove(lines.begin(), lines.end(), workingString), lines.end());
                        if (!lines.empty()) {
                            auto i=lines.begin();
                            auto e=lines.end()-1;
                            for (; i!=e; ++i) {
                                saveTasks << *i << '\n';
                            }
                            saveTasks << *i;
                        }*/



                        // This writes a copy of the tasks.dat file, minus the task that the user elected not to be notified of.'
                        while(getline(tasksClone, testBuffer)){
                            if(testBuffer == workingString){
                                // This condition does nothing. Essentially erasing the 'completed' task from the list.
                            }
                            else if(testBuffer != workingString && tasksClone.eof()){
                                // This writes everything except the specified task to taskbuffer.dat
                                saveTasks << testBuffer;
                            }
                            else { 
                                saveTasks << testBuffer << '\n';
                            }
                        }                   
                    }                       
                }
            }       
        }
    }
    else{
        cout << "The tasks file is empty, you must not have any tasks!" << endl;
    }

I hope that question makes sense!

Thanks

Marcus

UPDATE: Reworked the code, again. After telling it to delete 1 task, it never runs this loop. Current code:

while(getline(tasksClone, testBuffer)){
        if(testBuffer == workingString){
            // This condition does nothing. Essentially erasing the 'completed' task from the list.
        }
        else if(testBuffer != workingString && tasksClone.eof()){
            // This writes everything except the specified task to taskbuffer.dat
                saveTasks << testBuffer;
                            }
        else { 
                saveTasks << testBuffer << '\n';
        }

}

Input file:

test1   2012/12/13  10  0;
test2   2012/12/23  20  0;
test3   2012/12/31  28  0;
\n

Output file (after telling it to delete test1 and 2):

test2   2012/12/23  20  0;
test3   2012/12/31  28  0;
\n
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:47:55+00:00Added an answer on June 15, 2026 at 12:47 pm

    I solved my problem, just in case anyone wants to know. It’s not as memory efficient as it could be, but it functions:

    // Reads the file, checks if it's due, and if it's due prompts user to either save or delete the task.
    // Captures a clean copy of the line, in its entirety, and stores it to workingString.
    while(getline(checkTasks,workingString)){
        countTheDays = 0;
        // Handles newline characters.
        char nlcheck;
        checkTasks.get(nlcheck);
        if(nlcheck == '\n'){
        }
        else{
            checkTasks.unget();
            // Breaks that line up into more usable pieces of information.
            getline(check2,tName, '\t');
            getline(check2,tDate, '\t');
            getline(check2,trDate, '\t');
            getline(check2,tComplete, '\n');
            // Converts the string from of these pieces into usable integers.
            stringstream(tDate.substr(0,tDate.find_first_of('/'))) >> year;                       stringstream(tDate.substr(tDate.find_first_of('/')+1,tDate.find_last_of('/'))) >> month;                  stringstream(tDate.substr(tDate.find_last_of('/')+1,tDate.length()-1)) >> day;
            stringstream(tComplete) >> checkComplete;
            stringstream(trDate) >> checkReminder;              
    
            // Adds the number of days until your task is due!
            if(year != date[0]){
                for(int i = date[1]; i <= 12; i++){
                    countTheDays += System::DateTime::DaysInMonth(date[0], i);                      
                }
                countTheDays-= date[2];
                for (int i = 1; i<= month; i++){
                    countTheDays +=System::DateTime::DaysInMonth(year, i);
                }
                countTheDays -= (System::DateTime::DaysInMonth(year, month) - day);
            }
            else if(month != date[1]){
                for(int i = date[1]; i <= month; i++){
                    countTheDays += System::DateTime::DaysInMonth(date[0], i);
                }
                countTheDays -= (date[2]);
                countTheDays -= (System::DateTime::DaysInMonth(year, month) - day);
            }
            else{
                countTheDays+= System::DateTime::DaysInMonth(date[0], month);
                countTheDays -= (System::DateTime::DaysInMonth(year, month) - day);
                countTheDays -= date[2];                    
            }
    
            // If the task is nearing it's due date (the time frame specified to be notified) it'll notify user. 
            if(countTheDays <= checkReminder){
                if( countTheDays < 0){
                    cout << endl << endl << tName << " is past due!" << endl;
                    cout << "Should I keep reminding you about this task? Enter Y or N. ";
                    cin >> continueToRemind;
                }
                else{
                    cout << endl << endl << tName << " is due in " <<countTheDays << " days! Don't forget!" << endl;
                    cout << "Should I keep reminding you about this task? Enter Y or N. ";
                    cin >> continueToRemind;
                }
    
                // If user doesn't want to be reminded, begins process of converting that line in the file to usable info
                // and 'overwriting' the old file by creating a new one, deleting the old one, and renaming the new one.
                if(continueToRemind == "n" || continueToRemind == "N"){
                    fileModified = true;
                    // Adds workingString to deleteTasks[] to be compared against later.
                    deleteTasks.push_back(workingString);
                }
            }
        }
    }
    
            int match = 0;
            // Iterates through tempTasks.dat and compares lines to workingString.
            while(getline(tasksClone, testBuffer)){
                for(int i = 0; i< deleteTasks.size(); i++){
                    // If a match is found, it sets the match flag to delete that line.
                    if(testBuffer ==  deleteTasks[i]){
                        match = 1;
                    }
                }
                // Deletes that task.
                if(match == 1){
                    //Do nothing, erasing the task
                }
                // If EOF, writes only the task, without a newline character.
                else if(tasksClone.eof()){
                    saveTasks << testBuffer;
                }
                // If !EOF, also writes a newline character.
                else{
                    saveTasks << testBuffer << '\n';
                }
                match = 0;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see below code snippt: <?php //Sets the update and indicator elements by DOM
update: the answer from virtualeyes (below) looks pretty nice: but now a bit code-sanititzing
edit: after i update the latest code and now i see there are two
(see update below) While running within the VisualStudio 2010 environment, I can easily tell
UPDATE see below I am not sure how to populate a list or vector
UPDATE (spoiler): This question is answered (see David Carlisle answere below) and it looks
See the code below. The drive() is in the scope , I can drive
As you can see in the code below, I have an Abstract Base Class
(Answer found. See below.) In the following code, I am updating about 350,000 records
UPDATE - No need to answer this now, I have solved below. Hi, I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.