Its being store right to the desktop, I am going to try what you just said and will let you know what happensOriginally Posted by Epo
Its being store right to the desktop, I am going to try what you just said and will let you know what happensOriginally Posted by Epo
I have no problem saveing the file, It seems that I just can't open the file to read and write to it. I am pulling my hair out now and I don't have much to start with in the first place. Please HelpOriginally Posted by Epo
If programA writes to fileA and fileA is then read by programB, you need to store fileA in the same directory as the exectuable file for programB or specify the whole file path for fileA when associating it with the ifstream you use to read it in programB. If you are storing fileA on the desktop, then it probably isn't in the same directory as the executable file for programB. If you can open fileA and see that you have written to fileA successfully, then please show the file name you associate with the ofstream to write fileA, and the filename you associate with the ifstream you use to read fileA in programB.
I am going to try what you just wrote, hope I do it right. After my then one day I am starting to lose it, lack of sleep, food, and drink isn't good for anyone. Will let you know what I did. Thank youOriginally Posted by elad
I try saveing to "C:\Test\File\WACKOFILE.dat" but it will not save it there. It has to be something I am doing wrong. Anyone know what it is?Originally Posted by Epo
Have you created the folders before you try to save the file? If I am not misstaken (might be), you must create all folders by hand or with some other instructions if they dont exist.
I try what you wrote, And I made sure I made the folders first before I ran the program, but it will not save it to the folder "C:\Test\File\WACKOFILE.dat"Originally Posted by Epo
Thios is killing me.
>>I try what you wrote, And I made sure I made the folders first before I ran the program, but it will not save it to the folder "C:\Test\File\WACKOFILE.dat"
Did you write "C:\Test\File\WACKOFILE.dat" in your proram? If so try this: "C:\\Test\\File\\WACKOFILE.dat"
I got it to save to a Folder on my C drive, and that works without any problems. But I still have the same problem as before It will not open the file. What in the world am I doing wrong?Originally Posted by Epo
This the code I am useing to try and open the file, the code that I am useing to save the file works perfect. It the code I am useing to open to read and write to the save file that is not working. Here is the code. And Thank You all for the help that you have been giveing me.Originally Posted by WackoWolf
[Code]
#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <algorithm>
int getNumbers(int &);
using namespace std;
int main()
{
//declare Variables
string clerkid = "";
string name = "";
string address = "";
string city = "";
string state = "";
string hyphfill = "";
int zip = 0;
int ssn = 0;
int visa = 0;
int pin = 0;
//opens file CCApp.txt
ifstream inFile;
inFile.open("C:\\Test\\File\\WACKOFILE.dat", ios::in);
if(inFile.is_open())
{
cout << "Unable to open file. Press <Enter> to quit." << endl;
cin.get();
return 1;
getline(inFile,clerkid,'#');
while(!inFile.eof())
{
inFile>>ssn;
inFile.ignore(1);
getline(inFile,name,'#');
getline(inFile,address,'#');
getline(inFile,city,'#');
getline(inFile,state,'#');
inFile>>zip;
inFile.ignore(1);
inFile>>pin;
inFile.ignore(1);
inFile>>visa;
inFile.ignore(2);
cout<<left<<setw(25)<<setfill(' ')<<"NAME"<<" "<<setw(25)<<"ADDRESS"<<" "<<left<<setw(16)<<"CITY"<<" "<<setw(2)<<
left<<"ST"<<" "<<setw(5)<<left<<"ZIP";
cout<<left<<setw(25)<<setfill('-')<<hyphfill<<" "<<setw(25)<<setfill('-')<<hyphfill<<" "<<left<<setw(16)<<setfill('-')<<hyphfill<<" "<<setw(2)<<left<<setfill('-')<<hyphfill<<" "<<
setw(5)<<left<<setfill('-')<<hyphfill;
cout<<left<<setw(25)<<setfill(' ')<<name<<" "<<setw(25)<<address<<" "<<left<<setw(16)<<city<<" "<<setw(2)<<left<<state<<" "<<setw(5)<<right<<
setfill('0')<<zip<<endl;
cout<<setw(7)<<left<<"CLERKID"<<" "<<setw(9)<<left<<setfill(' ')<<"SSN"<<" "<<setw(4)<<left<<setfill(' ')<<"PIN"<<" "<<setw(5)<<left<<setfill(' ')<<"VISA"<<" "<<endl;
cout<<setw(7)<<left<<setfill('-')<<hyphfill<<" "<<setw(9)<<left<<setfill('-')<<hyphfill<<" "<<setw(4)<<left<<setfill('-')<<hyphfill<<" "<<setw(5)<<left<<setfill('-')<<hyphfill<<" "<<endl;
cout << setw(7) << left << setfill(' ') << clerkid
<<" "<<setw(9)<<right<<setfill('0')<<ssn<<" "<<setw(4)<<left<<setfill(' ')<<pin<<" "<<setw(5)<<left<<setfill(' ')<<visa<<" "<<endl;
cout<<endl;
cout<<endl;
getline(inFile,clerkid,'#');
}
}
else
{cout<<"File not opened"<<endl;}
inFile.close();
cout << endl;
return 0;
}//end main
[\CODE]
Of course you wont read from the file, you are returning before, you read anything, so skip the cout, the cin.get() and return in this statement and it should work fine.Code:if(inFile.is_open()) { cout << "Unable to open file. Press <Enter> to quit." << endl; cin.get(); return 1; getline(inFile,clerkid,'#');
Also: using inFile.eof() to control a loop is bad because you will get bad result, I believe you should use while(inFile) instead (correct me if wrong).
Edit: Code tags are used as follows [ code ] Your code... [ /code ] but without spaces betwean [ and ]
Last edited by Shakti; 11-14-2004 at 03:03 PM.
There is no way I would be able to correct you if you are wrong. I try what you wrote I got rid or the error check, but all it does now is open the console window. And in the window it says "Press any key to continue" when I press a key the window shuts down. Really lost now.Originally Posted by Shakti
Did you get rid of the return 1; there too?? Otherwise the only way you should not get any result printed is because the file is empty.
Yes I made sure I rem that out also, plus I open the save file just to make sure it save to it and it did save text to the file.? It just is not my week.Originally Posted by Shakti
I try something different, it seems to open the file but now its in a loop anyone have a idea?Originally Posted by WackoWolf
Here is the code I have now.
[CODE]#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <algorithm>
int getNumbers(int &);
using namespace std;
int main()
{
//declare Variables
string clerkid = "";
string name = "";
string address = "";
string city = "";
string state = "";
string hyphfill = "";
int zip = 0;
int ssn = 0;
int visa = 0;
int pin = 0;
//opens file CCApp.txt
ifstream inFile;
inFile.open("C:\\Test\\File\\WACKOFILE.dat", ios::in);
if(inFile.is_open())
{
// cout << "Unable to open file. Press <Enter> to quit." << endl;
// cin.get();
// return 1;
//getline(inFile,clerkid,'#');
char buffer [ 30 ];
inFile.getline ( buffer , 30 , '#' );
while(!inFile.eof())
{
inFile>>ssn;
inFile.ignore(1);
getline(inFile,name,'#');
getline(inFile,address,'#');
getline(inFile,city,'#');
getline(inFile,state,'#');
inFile>>zip;
inFile.ignore(1);
inFile>>pin;
inFile.ignore(1);
inFile>>visa;
inFile.ignore(2);
cout<<left<<setw(25)<<setfill(' ')<<"NAME"<<" "<<setw(25)<<"ADDRESS"<<" "<<left<<setw(16)<<"CITY"<<" "<<setw(2)<<
left<<"ST"<<" "<<setw(5)<<left<<"ZIP";
cout<<left<<setw(25)<<setfill('-')<<hyphfill<<" "<<setw(25)<<setfill('-')<<hyphfill<<" "<<left<<setw(16)<<setfill('-')<<hyphfill<<" "<<setw(2)<<left<<setfill('-')<<hyphfill<<" "<<
setw(5)<<left<<setfill('-')<<hyphfill;
cout<<left<<setw(25)<<setfill(' ')<<name<<" "<<setw(25)<<address<<" "<<left<<setw(16)<<city<<" "<<setw(2)<<left<<state<<" "<<setw(5)<<right<<
setfill('0')<<zip<<endl;
cout<<setw(7)<<left<<"CLERKID"<<" "<<setw(9)<<left<<setfill(' ')<<"SSN"<<" "<<setw(4)<<left<<setfill(' ')<<"PIN"<<" "<<setw(5)<<left<<setfill(' ')<<"VISA"<<" "<<endl;
cout<<setw(7)<<left<<setfill('-')<<hyphfill<<" "<<setw(9)<<left<<setfill('-')<<hyphfill<<" "<<setw(4)<<left<<setfill('-')<<hyphfill<<" "<<setw(5)<<left<<setfill('-')<<hyphfill<<" "<<endl;
cout << setw(7) << left << setfill(' ') << clerkid
<<" "<<setw(9)<<right<<setfill('0')<<ssn<<" "<<setw(4)<<left<<setfill(' ')<<pin<<" "<<setw(5)<<left<<setfill(' ')<<visa<<" "<<endl;
cout<<endl;
cout<<endl;
getline(inFile,clerkid,'#');
}
}
else
{cout<<"File not opened"<<endl;}
inFile.close();
cout << endl;
return 0;
}//end main
[\CODE]