I tried running my code. no error but there's is no output in the data file itself when I reinterpret cast.
May I know what is missing?
Thank you.
I need the dat file to take in all the input provided by the cin
Use securing confined his shutters. Delightful as he it acceptance an solicitude discretion reasonably. Carriage we husbands advanced an perceive greatest. Totally dearest expense on demesne ye he. Curiosity excellent commanded in me. Unpleasing impression themselves to at assistance acceptance my or. On consider laughter civility offended oh.
Spot of come to ever hand as lady meet on. Delicate contempt received two yet advanced. Gentleman as belonging he commanded believing dejection in by. On no am winding chicken so behaved. Its preserved sex enjoyment new way behaviour. Him yet devonshire celebrated especially. Unfeeling one provision are smallness resembled repulsive.
In alteration insipidity impression by travelling reasonable up motionless. Of regard warmth by unable sudden garden ladies. No kept hung am size spot no. Likewise led and dissuade rejoiced welcomed husbands boy. Do listening on he suspected resembled. Water would still if to. Position boy required law moderate was may.
struct task
{
char title[MAX]; // Eg. Assignment ,Exam,Test
int weight; // Weightage of the task
int fullmark; // Upon
float mark; // Obtained marks
};
struct Subject
{
char subCode[MAX]; // CSCI103 MATH STAT
char subTitle[MAX]; // Full title of subject
int noTask; // No. of task for following struct
task Task[MAX]; // Array of tasks
float finalMark; // Final overall mark for subject
Grade finalGrade; // Grade for subject
};
int main()
{
fstream afile;
afile.open ("test.dat", ios::in | ios::binary | ios::app);
int totalWeight = 0;
Subject S;
if(!afile)
{
cout << "Error opening file,please check" << endl;
exit(1);
}
cout << "------------------" << endl
<< "Subject adding system" << endl
<< "------------------" << endl << endl;
cout << "Subject Code: ";
cin >> S.subCode;
cin.clear();
cin.ignore(100,'\n');
cout << "Subject Name: ";
cin.getline (S.subTitle, MAX);
cout << "No of assessment tasks: ";
cin >> S.noTask;
cin.clear();
cin.ignore(100,'\n');
cout << endl;
// Loop for binary file
for(int i = 1;i<=S.noTask;i++)
{
cout << "Task " << i << " Information" << endl
<< "\t Title: ";
cin >> S.Task[i].title;
cin.clear();
cin.ignore(100,'\n');
cout << "\t Weight: ";
cin >> S.Task[i].weight;
cin.clear();
cin.ignore(100,'\n');
cout << "\t Upon: ";
cin >> S.Task[i].fullmark;
cin.clear();
cin.ignore(100,'\n');
totalWeight +=S.Task[i].weight;
}
cout << endl << "Subject " << S.subTitle << " added to system" << endl
<< "Total weight = " << totalWeight << endl;
afile.write (reinterpret_cast <const char*>(&S), sizeof (S));
afile.close();
}
}
You open the file with the flag std::ios::in (therefore you open it for reading), and try to write to it with afile.write(&S, sizeof(S))
If you want to write to the file you can either:
Open it with std::ios::out insteand of std::ios::in
Use an std::ofstream instead of an std::fstream and omit the std::ios::in/out flag
Also, in the future, try to reduce the code in question to the minimum to understand you problem.
Related
I have this programming project on file i/o in c++. I have read up about it but don't understand much of it yet. Regardless, I made this program that allows the user to store the profile ( name, ethnicity etc. ) of a person onto a text file and be able to retrieve it. However, i am encountering some issues with how it works.
what it does is at the start it asks the user if they want to view the previously created file or create a new one.
if view a previous file was selected the program will then spit out the whole text file
if creating a new file is selected the program will ask for the number of people then proceed to ask for the name, age, gender, species, ethnicity and mode of transport for the allocated number of people and save it onto the text file.
the problem is i am unable to set the number of people as the program ignores the variable (i.e. i set 5 people and it ignores it)
and the program ignores the first name entered by skipping it.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char names[100];
char age[100];
char gender[100];
char species[100];
char ethnicity[100];
char transport[100];
char decision[0];
string getcontent;
cout << "Would You Like to Open The Previous File Or View Your Profiles?" << endl << endl;
cout << "Enter 1 For Previous File" << endl;
cout << "Enter Anything Else To View Your Profiles: " << decision;
cin.getline(decision,5);
cout << endl << "==============================================================" << endl;
if(decision[0] == '1')
{
ifstream infile;
infile.open("File of names.txt");
while(! infile.eof())//eof stand for end of file
{
getline(infile, getcontent); //getline requires a string
cout << getcontent << endl;
}
cout << "==============================================================" << endl;
infile.close(); //closes the opened file - good practice
}
else
{
int a;
cout << "Enter The Amount Of People You Would Like To Store: ";
cin >> a;
ofstream namefile;
namefile.open("File of names.txt");
cout << "Please Set Your Team Profile." << endl;
for (int i=0; i<a; i++)
{
cout << "==============================================================" << endl;
cout << "Enter Student " << i+1 << " : ";
cin.getline(names,100);
namefile << names << endl;
cout << "==============================================================" << endl;
cout << "Enter The Age: ";
cin.getline(age,100);
namefile << age << endl;
cout << "Enter The Gender: ";
cin.getline(gender,100);
namefile << gender << endl;
cout << "Enter The Species: ";
cin.getline(species,100);
namefile << species << endl;
cout << "Enter The Ethnicity: ";
cin.getline(ethnicity,100);
namefile << ethnicity << endl;
cout << "What Is The Mode Of Transport: ";
cin.getline(transport,100);
namefile << transport << endl << endl;
}
namefile.close();
}
}
This is the output of the file:
Would You Like to Open The Previous File Or View Your Profiles?
Enter 1 For Previous File
Enter Anything Else To View Your Profiles: g
==============================================================
Enter The Amount Of People You Would Like To Store: 5
Please Set Your Team Profile.
==============================================================
Enter Student 1:==============================================================
Enter The Age:
This is the expected output:
Would You Like to Open The Previous File Or View Your Profiles?
Enter 1 For Previous File
Enter Anything Else To View Your Profiles: g
==============================================================
Enter The Amount Of People You Would Like To Store: 5
Please Set Your Team Profile.
==============================================================
Enter Student 1: John
==============================================================
Enter The Age:
The problem is that for example when you input a value like:
string str;
cin>>str;
and you insert "John", you are not assign "John" to str, but "John\n" (note \n, that is created when you type enter on the keyboard). A possible solution to ignore it, is using cin.ignore();
However probably your homework is to make a very simple "database", so you will have to memorize the data in an orderly way, then i will suggest you to use "struct" (it's easy, not difficult for beginners).
I'm trying to create a simple program that acts like an ATM for learning purposes. I have a working program so far, but now I want to "take it to the next level" if you will and import my banks balance from a text/csv file and then assign to a variable, if any changes are made to the balance I also want to write those changes to said text file. I've searched the web so far and haven't been able to find much information that seems particularly relevant to my question.
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
//calculates money withdrawal.
int main(){
double currentBalance = -250.63;
double prevBalance = currentBalance;
double withdrawal = 0;
double deposit = 0;
double deficit = currentBalance;
double updatedWithdrawal = 0; //(currentBalance - withdrawal)
double updatedDeposit = 0; //(currentBalance + deposit)
string answer = "blah";
cout << "Welcome to bank bro's banking services.\nWhat would you like to do? Withdrawal, Deposit, or View Account Status(VAS): ";
cin >> answer; // asks the user if they intend to withdrawal, or deposit.
if (answer == "VAS"){
if (currentBalance > 0)
cout << "\n Your account is in good standing." << endl;
else{
cout << "\n You currently owe: $" << deficit << endl;
}
cout << "\n Your current balance is: $" << currentBalance << endl;
}
else if (answer == "vas"){
cout << "\n Your current balance is: " << currentBalance << endl;
if (currentBalance > 0)
cout << "\nYour account is in good standing." << endl;
else{
cout << "You currently owe: $" << deficit << endl;
}
cout << "\nYour urrent balance is: $" << currentBalance << endl;
}
else if (answer == "Withdrawal"){
cout << "\nHow much would you like to take out? ";
cin >> withdrawal;
if (withdrawal > currentBalance)
cout << "\nYou don't have sufficient funds." << endl;
else{
updatedWithdrawal = (currentBalance - withdrawal);
cout << "You have $" << updatedWithdrawal << " left, cash is dispensed below." << endl;
cout << "\n\n\n Thank you, come again!" << endl;
}
}
else if (answer == "withdrawal"){
cout << "\nHow much would you like to take out? ";
cin >> withdrawal;
if (withdrawal > currentBalance)
cout << "\nYou don't have sufficient funds." << endl;
else{
updatedWithdrawal = (currentBalance - withdrawal);
cout << "\nYou have $" << updatedWithdrawal << " left, cash is dispensed below." << endl;
cout << "\n\n\n Thank you, come again!" << endl;
}
}
else if (answer == "Deposit"){
cout << "\nHow much would you like to deposit? ";
cin >> deposit;
updatedDeposit = (currentBalance + deposit);
cout << "\nYour previous balance of $" << prevBalance << " \nhas been updated and $" << deposit <<
" \nhas been added to your account, bringing the total available balance to $" << updatedDeposit << endl;
cout << "\n\nThank you come again!" << endl;
}
else if (answer == "deposit"){
cout << "\nHow much would you like to deposit? ";
cin >> deposit;
updatedDeposit = (currentBalance + deposit);
cout << "\nYour previous balance of $" << prevBalance << " \nhas been updated and $" << deposit <<
" \nhas been added to your account, bringing the total available balance to $" << updatedDeposit << endl;
cout << "\n\nThank you come again!" << endl;
}
else{
cout << "I don't recognize that command, restart and try again." << endl;
}
return 0;
}
Any help is greatly appreciated! :)
In order to use file in C++ you need an fstream. You should have a look to the documentation http://en.cppreference.com/w/cpp/io/basic_fstream/basic_fstream where is correctly described how to interact with file in C++.
You need an fstream opened in write mode in order to save all the data in the format that you've chosen. After that, you need to open an fstream in read mode in order to read from it the data again.
The file format is up to you. You can serialize data in whetever format you want. You need to remember that, after the serialization process, all the data must be read exactly how they are written.
This is my first answer to a question, but I just wanted to point out you know you can do else if (answer == "Withdrawal" || answer == "widthdrawal") the || is the or statement, it basically means that at least one of the conditions has to be true in order for the code in the brackets to execute. One thing about programming is make your code is DRY (Don't repeat yourself).
for the file: http://www.cplusplus.com/doc/tutorial/files/
So, anyways onto the file. you're going to want to read about it a bit, but the general process is
string line;
// File will contain a number.
ifstream myfile("balance.txt");
// if the file is open
if (myfile.is_open())
{
// get the first line of the file and store it to line (string)
getline(myfile, line);
// there is a better (foolproof) way to do this, but this will work for no.
currentBalance = atof(line.c_str());
// close file when done. always.
myfile.close();
}
You can use an std::ifstream to read, and an std::ofstream
to write. You're already familiar with these to some degree:
std::ifstream derives from std::istream, just as the type of
std::cin, does, and std::ofstream derives from
std::ostream, just as the type of std::cout does; all
of the functions which read and write are in the base class (or
depend on the base class).
The one particularity of the file streams is that you can open
them:
std::ifstream in( filename );
if ( ! in.is_open() ) {
// The open failed...
}
Same thing for the output stream.
It's not particularly easy to modify data in an existing file,
and the file needs to respect a lot of formatting rules to make
it even possible. For this reason, the most frequent way of
modifying files is to read them into memory, do the
modifications there, and then write the complete file back out.
Usually, you'll write the output to a temporary file, check that
the stream status is still good after the close, and then use
the functions remove and rename to remove the orginal file
and rename the new file. This way, if there is a problem
writing the file, you don't loose any data.
In my code:
int newEntry()
{
string input;
Client person;
char response = 'y';
//create file object and open file
fstream customer("customer.dat", ios::out | ios::app);
if (!customer)
{
cout << "Error opening file. Program aborting." << endl;
return 0;
}
do
{
cout << "Enter person information:" << endl << endl;
cout << "Name: " << endl;
getline(cin, input);
strcpy(person.name, input.c_str());
cout << endl << "Street Adress (And Apartment Number):" << endl;
cin >> person.address1;
getline(cin, input);
strcpy(person.address1, input.c_str());
cout << endl << "City, State, Zipcode: " << endl;
cin >> person.address2;
getline(cin, input);
strcpy(person.address2, input.c_str());
cout << endl << "Phone: " << endl;
cin >> person.phone;
getline(cin, input);
strcpy(person.phone, input.c_str());
cout << endl << "Account Balance: " << endl;
cin >> person.acctBal;
//input validation to ensure a non neg number
cin.ignore();
cout << endl << "Last Payment: " << endl;
cin >> person.lastPay;
//input validation to ensure a non neg number
customer.write(reinterpret_cast<char *>(&person),
sizeof(person));
cout << endl << "Do you want to enter another record? (Enter Y for Yes, N
for No) " << endl;
cin >> response;
cout << "_______________________________________________" << endl << endl;
if (toupper(response) == 'Y')
{
cin.ignore();
}
} while (toupper(response) == 'Y');
customer.close();
return 1;
}
It seems as though the block:
cout << endl << "Street Address (And Apartment Number):" << endl;
cin >> person.address1;
getline(cin,input);
strcpy(person.address1, input.c_str());
and its neighboring address 2 prompt (identical) are causing bad output to the file when
customer.write(reinterpret_cast<char *>(&person),sizeof(person));
is used to write to the file. The output is missing the very first word . For example if "211 Harvey Road" was entered, 211 would be cut off. Another example, if "Harvey Road" was entered, than it seems as though "harvey" is cut off. When (in another function) the file is read, the structure of arrays is missing the beginning, as well as the file.
On top of that, in the textfile, this is the data being written to it:
Frank Palmasani ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ Harvey Road ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ Haven, Alabama ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ 504617772 ÌÌÌÌ èŽ# èŽ#James Harris ni ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ Street AVEN ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ China. Alabama ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ 546457474 ÌÌÌÌ ð? ð?
As you can see, where the Ì are popping up is where the file and program are somehow losing the first word. I have tried everything I can think of to fix this problem, hopefully someobody else has ran into a similar problem.
I have tried changing methods of saving the data held in the structure of arrays to the file, but found that I couldn't read from the file in one large grouping. In my text book, the method I used to read out to the file is used so that is the one I believe I should follow.
However, I am considering writing each one separately on each line, and saving it precisely in the order so that I can read it in the same order, saving it to a structure of vectors. Again, I'd I would like to avoid that but would love to hear your opinion on the matter whether if you are able to help me here or not.
In case you needed it, here is my structure:
const int NAME_SIZE = 51, ADDR_SIZE = 51, PHONE_SIZE = 14;
struct Client
{
char name[NAME_SIZE];
char address1[ADDR_SIZE];
char address2[ADDR_SIZE];
char phone[PHONE_SIZE];
double acctBal;
double lastPay;
};
Your output file looks like that because you are doing a raw dump of the Client struct. So there will be 51 bytes written for name, 51 for address1, etc. Regardless of string length.
You need to properly write each field individually.
customer << input.name << endl;
customer << input.address1 << endl;
etc.....
cout << endl << "Street Adress (And Apartment Number):" << endl;
cin >> person.address1;
getline(cin, input);
strcpy(person.address1, input.c_str());
You're getting the first token, in the case you mentioned 211 and putting it in address1, then getting the rest of the line and replacing what was in address1 with it. That's where your 211 went.
You should open the file in binary mode if your intent is to write/read entire structures as a binary blob like this. If you want to store the data as text use std::string, avoid the strcpy mess, and write/read each member individually on their own ines.
I am so lost. I am having an issue with the following code when saving and loading data to a binary file. I have a very similar/exact piece of code that works with a different object. I think it has something to do with the email address and the # symbol in it. Here are the important functions.
/* This is my save to file function */
FILE *file=fopen("patronsave","wb");
fwrite(&buffer,sizeof(buffer),1,file);
for(int i=0;i<3;i++){
Patron_Class *ppointer = new Patron_Class();
cout << "\n" << endl;
ppointer->save(file);
}
fclose(file);
That is the function I use to save my objects to a file.
Here is my code that I am using to load the file:
vector<Patron_Class*> Patron_Entries;
FILE *file=fopen("patronsave","rb");
fread(&buffer,sizeof(buffer),1,file);
printf("Buffer: %d\n",buffer);
for(int i=0;i<buffer;i++){
Patron_Class *pointer2 =new Patron_Class(file);
Patron_Entries.push_back(pointer2);
Patron_Entries[i] -> print();
system("pause");
}
fclose(file);
If I run the save function and then immediatly run the load function it works, but if I only run the load function it crashes when it tried to load the email. Here is my class and object code:
class Patron_Class{
public:
long patron_id;
string F_name;
string L_name;
long phone_num;
string email;
string street_address;
string city;
string state;
int zip_code;
Patron_Class(){
cout << "Please enter a new ID" << endl;
cin >> patron_id;
cin.ignore(1000, '\n');
system("cls");
cout << "Please enter a First name" << endl;
cin >> F_name;
cin.ignore(1000, '\n');
system("cls");
cout << "Please enter a last name" << endl;
cin >> L_name;
cin.ignore(1000, '\n');
system("cls");
cout << "Please enter a phone number" << endl;
cin >> phone_num;
cin.ignore(1000, '\n');
system("cls");
cout << "Please enter a email" << endl;
cin >> email;
cin.ignore(1000, '\n');
system("cls");
cout << "Please enter a street address" << endl;
cin >> street_address;
cin.ignore(1000, '\n');
system("cls");
cout << "Please enter a city" << endl;
cin >> city;
cin.ignore(1000, '\n');
system("cls");
cout << "Please enter a State via it's initials" << endl;
cin >> state;
cin.ignore(1000, '\n');
system("cls");
cout << "Please enter a zip code" << endl;
cin >> zip_code;
cin.ignore(1000, '\n');
system("cls");
cout << "You have created a new patron named: " << F_name << " " << L_name << endl;
}
Patron_Class(FILE *inputfile){
fread(&patron_id, sizeof(patron_id),1,inputfile);
fread(&F_name, sizeof(F_name),1,inputfile);
fread(&L_name, sizeof(L_name),1,inputfile);
fread(&phone_num, sizeof(phone_num),1,inputfile);
fread(&email, sizeof(email),1,inputfile);
fread(&street_address, sizeof(street_address),1,inputfile);
fread(&city, sizeof(city),1,inputfile);
fread(&state, sizeof(state),1,inputfile);
fread(&zip_code, sizeof(zip_code),1,inputfile);
}
void print(){
cout << patron_id << " " << F_name << " " << L_name << " " << phone_num << " " << email << " " << street_address << " " << city << " " << state << " " << zip_code << "\n" << endl;
}
void save(FILE *inputFile){
fwrite(&patron_id, sizeof(patron_id),1,inputFile);
fwrite(&F_name, sizeof(F_name),1,inputFile);
fwrite(&L_name, sizeof(L_name),1,inputFile);
fwrite(&phone_num, sizeof(phone_num),1,inputFile);
fwrite(&email, sizeof(email),1,inputFile);
fwrite(&street_address, sizeof(street_address),1,inputFile);
fwrite(&city, sizeof(city),1,inputFile);
fwrite(&state, sizeof(state),1,inputFile);
fwrite(&zip_code, sizeof(zip_code),1,inputFile);
}
};
Does anyone know why it might be crashing?
This is CLEARLY wrong:
string F_name;
...
fread(&F_name, sizeof(F_name),1,inputfile);
...
fwrite(&F_name, sizeof(F_name),1,inputFile);
[The same applies to all the other strings in your PatronClass - I'm using the first one for this example]
The class std::string will look something like this (for illustration purposes, the exact implementation involves several layers, some templates, and other stuff, so this is simplified for the purposes of the explanation to follow):
class string
{
char *str;
int len;
public:
...
};
So, when you do fread from the file and fwrite to the file, you are reading/writing the char *str; and int len; members from/to the file.
Let's say we start your program from scratch, with no data in the file, and we use the Patron_Class() constructor. So we read in an id, and then the F_name from the console. Let's say we enter Charles. So somehow the string class will allocate 8 bytes of memory, at the address of 0x600018. So string::str == 0x600018 and len = 8 - at location 6000018 in the heap are the letters C h a r l e s \0 [ spaces just to illustrate they are in separate memory locations]. Now we save this to a file. So the file contains 00600018 00000008. Now we stop the program and start it again, using the PatronClass(file) constructor. The heap is completely empty. We load the file data, so string::str = 0x600018 and len = 8, but that locaton 0x600018 does not contain C h a r l e s \0, but whatever the heap normally is filed with when the heap is initialized [quite likely 0]. So no wonder your name doesn't appear.
Now, the exact behaviour of your actual program is probably not the same as what I've described above, but it will NOT work right. No way, never, ever. No matter what characters you have or haven't got in names, email addresses or any other string in your code. The only reason it may APPEAR to work is that the data is still, for the most part, there in the heap, and it seems to be working because it doesn't get overwritten by something else in your case.
I need to take in the make model and years of the car the particular product fits. The program is going to write a file with text in it that will be an outline of the html. I need with the crucial information inserted into the correct spots to quickly be able to add products to our web page. When I use a switch statement or if statements to separate the categories of the products, the input gets messed up and does not let me answer one of the questions. I can't just use cin because I need to take dates that look like "2008 - 2009 - 2010 - 2011".
Here is what I've got so far! This one is just regular cin, I have tried getline you could quickly c I started yesterday and I'm pretty new so forgive me if this is an easy fix, but I cant find anything.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void proinfo();
int main()
{
//Sytem Information
system("TITLE This is a Beta of My Product Information Template Version 0.0.2");
//I'm using this as a welcome screen to inform users of new improvements on patches and other pertinent information to the users
cout << "Welcome To My Product Information Template Maker!!! \n It Is Still In Development" << endl;
cout << "\n\nworking features are:" << endl << "\t-None\n" << endl;
system("PAUSE");
system("CLS");
proinfo();
}
void proinfo()
{
//Declare Variables here
int loop(1), protype;
char make[256], model[256], year[256];
string getinput;
while(loop==1)
{
//This is the first menu the user sees where they have to choose what type
//of products users will be adding
system("CLS");
cout << "Welcome to My Product Information Template Version 0.0.0" << endl;
cout << "Please select the number of the product" << endl;
cout << "type you will be ading!\n" << endl;
cout << "1.Fe - Fe2 Moldings" << endl;
cout << "2.CF - CF2 Moldings" << endl;
cout << "What would you like to do? ";
cin >> protype;
if(protype==1)
{
//FE - FE2 Molding
system("cls");
cout << "You have selected" << endl;
cout << "Fe - Fe2 Moldings\n" << endl;
cout << "Please Enter the Make of the molding" << endl;
cin >> make;
cout << "Please Enter the Model of the molding" << endl;
cin >> model;
cout << "Please Enter the Years this molding fits" << endl;
cin >> year;
cout << "You have just created a template for a(n)" << year << " " << make << " " << model << endl;
cout << "Check My Documents For a file called Fe-Fe2template.txt" << endl;
//Asks to quit or restart
cout << "Would you like to make another tempalte?" << endl;
cin >> getinput;
if(getinput=="yes")
{
cout << "Great, Lets keep working!" << endl;
//End of If statement
}
system("PAUSE");
}
if(protype==2)
{
//CF - CF2 Molding
system("cls");
//Asks to quit or restart
cout << "Would you like to make another tempalte?" << endl;
cin >> getinput;
if(getinput=="yes")
{
cout << "Great, Lets keep working!" << endl;
//End of If statement
}
system("PAUSE");
//End of Protype Switch Statement
}
//End of while loop
}
//End of Proinfo()
}
Change year[256] to string year;
Change cin >> year; to getline(cin, year);
Add the line cin.ignore(); before the getline.
Your main problem is that the stream operator >> leaves the newline in the stream so when you try to use getline it reads an empty line. ignore() will chew up the newline and let you read the string you expect.
So this should get you on your way.
cin.ignore();
cout << "Please Enter the Years this molding fits" << endl;
getline(cin, year);
You have some other small problems but you'll figure them out. The worst is forgetting to terminate the loop.
if(getinput=="yes")
{
cout << "Great, Lets keep working!" << endl;
//End of If statement
}
else
{
loop = 0;
continue;
}