| | |
Why wont this work!!!
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hi. I am making a program, and I have a main section and a class that the main section tefers to in a .h file. The Ifstream part wont work, and i dont know why. Please help.
MAIN:
gatherUserData.h
Any help GREATLY appreciated
MAIN:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdio> #include <cstdlib> #include <string> #include <fstream> using namespace std; #include "logInInterface.h" #include "displayCopyright.h" #include "gatherUserData.h" // Prototype decelarations int passwordIn(); // Declare global variables copyrightMessage ds; int main(int nNumberofArgs, char* pszArgs[]) { // Clear the screen system("CLS"); passwordIn(); // After logInFunc form logInInterface.h is done, start the next action system("CLS"); ds.displayCopyright(); // Now ask the user to enter his/her library card number string inputNumber; cout << "\nPlease enter your library card number: "; cin >> inputNumber; userData uD; uD.displayData(inputNumber); system("PAUSE"); return 0; } int passwordIn() { system("CLS"); ds.displayCopyright(); logIn a; string passwordInput; cout << "\nPlease enter the password: "; cin >> passwordInput; a.logInFunc(passwordInput); if (a.statusInt == 0) { passwordIn(); } return false; }
gatherUserData.h
C++ Syntax (Toggle Plain Text)
class userData { public: userData() { number = "0"; } // Start a function that is able to display all of the user's data int displayData(string number) { userFound = false; ifstream displayData2; displayData2.open("userInformation.database.txt"); while (displayData2 >> tempData) { << number << "\n"; if (tempData == number) { userFound = true; // Now get the name displayData2 >> name; cout << "\n\nName: " << name << "\n"; // Now say the number cout << "Library Card Number: " // Now get the first part of expiration date displayData2 >> exp1; cout << "Expiration date: " << exp1; // Now get the second part displayData2 >> exp2; cout << " " << exp2; // Now the third displayData2 >> exp3; cout << " " << exp3 << "\n"; } displayData2.close(); } return false; } private: string number; string name; string exp1; string exp2; string exp3; string phone; string email; string pin; string fine; string out; string holdType; string holds; string availibleHolds; string tempData; bool userFound; };
Any help GREATLY appreciated
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
Ok the usual rant: I hate system("PAUSE") and CLS. They are non-portable, and I can clear my own screen if that is what I want!
Beyond that you haven't given us much to go on.
You don't test if displayData2 is successful? Does "userInformation.database.txt" exist / get opened, have Windows throw a fit about two dots in the name ?
Use
Then the lines
do not compile. Did you mean to pass the number to std::cout, and what is tempData??
You need something like
and then
tempData should be a userInfoRecord and your test should be
Beyond that you haven't given us much to go on.
You don't test if displayData2 is successful? Does "userInformation.database.txt" exist / get opened, have Windows throw a fit about two dots in the name ?
Use
if (disPlayData2.good()) to find out. Then the lines
c++ Syntax (Toggle Plain Text)
while (displayData2 >> tempData) { << number <<"\n";
You need something like
c++ Syntax (Toggle Plain Text)
class userInfoRecord { //stuff }; std::istream& operator>>(std::istream&,userInfoRecord&);
tempData should be a userInfoRecord and your test should be
if (tempData.getNumber()==number) Last edited by StuXYZ; Jan 31st, 2009 at 5:14 pm.
experience is the most expensive way to learn anything
Ok....I tried de-bugging the program before i did this post. I forgot all of the ifstream stuff and put a regular cout >> command. The program didnt even go on to that...
tempData is just the check to make sure the number matches the number on file...
userInformation.database.txt exists, but i dont kno if it opens...
does that help?
tempData is just the check to make sure the number matches the number on file...
userInformation.database.txt exists, but i dont kno if it opens...
does that help?
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
No:
The question what is tempData, was because it is declared string but you are comparing it with an integer.
What you have posted DOES NOT COMPILE, hence we can't debug it. What you have to do is POST code that compiles UNLESS you can't get it to compile and THEN post the error message that is causing the problem.
So does userInformation get opened.... I will repeat ADD
The question what is tempData, was because it is declared string but you are comparing it with an integer.
What you have posted DOES NOT COMPILE, hence we can't debug it. What you have to do is POST code that compiles UNLESS you can't get it to compile and THEN post the error message that is causing the problem.
So does userInformation get opened.... I will repeat ADD
c++ Syntax (Toggle Plain Text)
if (disPlayData2.good()) { std::cout<<"My file opened"<<std::endl;} else { std::cout<<"File not found/opened."<<std::endl;}
experience is the most expensive way to learn anything
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
well we still can't figure it out since I am certain that most of the members of this forum are not psychic.
You have not posted code that actually compiles, so I cannot guess what your real code does.
HOWEVER: I think it is that you don't match the first line/number and then you have only read in the first number not the whole line.
So you need a
You have not posted code that actually compiles, so I cannot guess what your real code does.
HOWEVER: I think it is that you don't match the first line/number and then you have only read in the first number not the whole line.
So you need a
c++ Syntax (Toggle Plain Text)
while(displayData.good()) { displayData>>tempData; if (tempData == number) { //stuff } else displayData.ignore(1024,'\n'); }
Last edited by StuXYZ; Feb 1st, 2009 at 4:55 pm.
experience is the most expensive way to learn anything
![]() |
Similar Threads
- Mouse and keyboard wont work (Windows NT / 2000 / XP)
- New Pc parts wont work correctly (Motherboards, CPUs and RAM)
- Help! My mouse wont work! (USB Devices and other Peripherals)
- mouse wont work! (Windows NT / 2000 / XP)
- i cant get my realtek card to work in rh8 (*nix Hardware Configuration)
- IE wont work with Antivirus Software (Web Browsers)
- IE wont work :-( (Web Browsers)
- Sound Card won't work on laptop (*nix Hardware Configuration)
Other Threads in the C++ Forum
- Previous Thread: Stumped on C++ code asterisks
- Next Thread: compile error?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





