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 1098549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:35:42+00:00 2026-05-17T00:35:42+00:00

having a bit of a problem with a recent project. The goal here is

  • 0

having a bit of a problem with a recent project. The goal here is to be able to input several lines of text containing a date in mm/dd/yyyy format followed by a whitespace and then a description of the event. I’ve accomplished actually allowing for multiple lines of text input (I think), but now I’m not exactly sure how to stop it. Is there a way to simply assume after a set amount of time, perhaps, that the user is done inputting? This problem is stressing me a lot as they never really addressed how to end user input, only how to accomplish multiple lines. We have to use the standard user input, not from text files which would be so much easier. Code below, please feel free to also tell me if I’ve made an unnoticed mistake elsewhere. I just need to be able to let the user finish the input so the program can re-order the events[] and output them.

calendar.cpp

#include <string>
#include <sstream>
#include <iostream>
#include <vector>

using namespace std;
#include "event.h"


int main(){
 // Maximum number of input lines
 const int MAX = 100; 

 // Array of pointers to events 
 Event *events[MAX];

 // Number of currently used pointers in events
 int size = 0;
 int i = 0;

 // Vector containing each input line as a string
 vector<string> vec (100);
 char temps[100];
 while(i < MAX){
  cin.getline(temps, 100);
  vec[i] = temps; 
  i++;
 }


 for(int i = 0; i < vec.size(); i ++){
   int found = vec[i].find("/");
   int tmo = atoi(vec[i].substr(0, found).c_str());
   int sfound = vec[i].find("/", found + 1, 6);
   int tda = atoi(vec[i].substr(found + 1, sfound - (found + 1)).c_str());
   int tye = atoi(vec[i].substr(sfound + 1, 4).c_str());
   string tdes = vec[i].substr(sfound + 6, vec[i].length() - (sfound + 6));
   events[size] = new Event(tmo, tda, tye, tdes);
   size++;
 }

 return 0;
}

event.cpp

#include <iostream>
#include <string>

using namespace std;
#include "event.h"

Event::Event(int mo, int da, int ye, string des){
 month = mo;
 day = da;
 year = ye;
 desc = des;
}

Event::~Event(){

}

void Event::print(){
 cout << month << "/" << day << "/" << year << " " << desc << endl;
}

event.h

#ifndef EVENT_H
#define EVENT_H

#include <iostream>
#include <string>
using namespace std;

class Event{
 public:
  Event(int mo, int da, int ye, string des);
  ~Event();
  void print();
 private:
  int month;
  int day;
  int year;
  string desc;
};

#endif

Thank you in advance for your help.

EDIT:

Replacing my while() loop with:

while ((i < MAX) && (!cin.eof()) {
  cin.getline(temps, 100);
  vec[i] = temps; 
  i++;
 }

Seemed promising but even after injecting an EOF marker with Ctrl + D (^D) as suggested, user input can still continue. Any reason why this might be happening?

  • 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-05-17T00:35:42+00:00Added an answer on May 17, 2026 at 12:35 am

    One way to accomplish this is to have the user press Ctrl-D to signify the End Of File. You will have to check for the end of file in your loop.

    while ((i < MAX) && (!cin.eof()) {
      cin.getline(temps, 100);
      vec[i] = temps; 
      i++;
     }
    

    This method has the additional benefit that a text file can be presented to the program instead of user input, and the same result will be achieved when the end of the file is reached.

    EDIT:

    Ctrl-Z is the EOF keystroke on Windows machines. The Ctrl-Z may have to be at the beginning of a line on that OS (see discussion at http://www.velocityreviews.com/forums/t356170-cant-detect-eof-from-stdin-on-windows-console.html for more on this topic)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.