Getting going in the right directionLooks for maybe a few pointers where I could figure out a few things
Page 1 of 1
10 Replies - 374 Views - Last Post: 15 June 2009 - 01:18 PM
#1
Getting going in the right direction
Posted 15 June 2009 - 05:20 AM
Now i'm still new to C++, but i've been starting to program a inventory console application in windows, and I just came to the point to where I want to be able to have files holding my information of products.
Like say I can have a menu to let me put in when I get more stock, then when I make a sale it can do all its math and whatnot.
The issue im having is figuring out how I need to write up the code, I got code that will create the file(I just made it "inventory.txt"), But I cannot find a tutorial on making previous stuff stay in files and just add on to what I had before. I know its something simple and right under my nose
I have been searching for like 48 hours and decided to finally ask the community.
Im not asking for code merely just a good shove in the right direction.
Thanks in advance,
CryptiC-
Replies To: Getting going in the right direction
#3
Re: Getting going in the right direction
Posted 15 June 2009 - 08:00 AM
CryptiC-, on 15 Jun, 2009 - 04:20 AM, said:
Now i'm still new to C++, but i've been starting to program a inventory console application in windows, and I just came to the point to where I want to be able to have files holding my information of products.
Like say I can have a menu to let me put in when I get more stock, then when I make a sale it can do all its math and whatnot.
The issue im having is figuring out how I need to write up the code, I got code that will create the file(I just made it "inventory.txt"), But I cannot find a tutorial on making previous stuff stay in files and just add on to what I had before. I know its something simple and right under my nose
I have been searching for like 48 hours and decided to finally ask the community.
Im not asking for code merely just a good shove in the right direction.
Thanks in advance,
CryptiC-
you need to set your flags for you file, so say:
ofstream FILE("inventory.txt",ios::app);
ios::app = All output operations are performed at the end of the file, appending the content to the current content of the file.
#4
Re: Getting going in the right direction
Posted 15 June 2009 - 09:19 AM
#5
Re: Getting going in the right direction
Posted 15 June 2009 - 10:31 AM
Again sorry if the post was covered a million times, my search efforts seemed fruitless, just looks like I wasn't looking around very well lol
Any other pages on file i/o or maybe a good reference sheet to print out?
When I come home from work and mess with it ill post my code up on here and let you guys take a look.. Im sure im doing so many wrong things or not very optimized so hopefully I can get more pointers lol
#6
Re: Getting going in the right direction
Posted 15 June 2009 - 10:39 AM
in my opinion, cstdio is good because it has functions that manipulate strings more carefully in detail. but fstream is good because it's fast to use with >> and << like
file << string;
would write a string straight into the txt without much headache.
#7
Re: Getting going in the right direction
Posted 15 June 2009 - 10:42 AM
Kanvus, on 15 Jun, 2009 - 09:39 AM, said:
in my opinion, cstdio is good because it has functions that manipulate strings more carefully in detail. but fstream is good because it's fast to use with >> and << like
file << string;
would write a string straight into the txt without much headache.
Thats another thing im gonna wanna be able to input a string for a name and some numbers per each entry into this file. I have to go do some reading on strings its sounding like haha
#8
Re: Getting going in the right direction
Posted 15 June 2009 - 10:55 AM
say file was opened as whatsfordinnermom.txt and only has one line,
nothing
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string hi;
fstream file;
file.open("whatsfordinnermom.txt");
file >> hi; // hi now has "nothing"
cout << hi; // show hi to screen
cout << endl;
system("PAUSE");
return 0;
}
everytime you repeat those two lines, it would skip to the next line in the whatsfordinnermom.txt file so you don't have to worry about moving the iterator forward.
This post has been edited by Kanvus: 15 June 2009 - 10:57 AM
#9
Re: Getting going in the right direction
Posted 15 June 2009 - 11:01 AM
Kanvus, on 15 Jun, 2009 - 09:55 AM, said:
say file was opened as whatsfordinnermom.txt and only has one line,
nothing
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string hi;
fstream file;
file.open("whatsfordinnermom.txt",ios::app);
file >> hi; // hi now has "nothing"
file.close();
cout << hi; // show hi to screen
cout << endl;
cin.get();
return 0;
}
everytime you repeat those two lines, it would skip to the next line in the whatsfordinnermom.txt file so you don't have to worry about moving the iterator forward.
This post has been edited by ImaSexy: 15 June 2009 - 11:03 AM
#10
Re: Getting going in the right direction
Posted 15 June 2009 - 11:10 AM
file.open("whatsfordinnermom.txt",ios::app | ios::out);
that would only allow output and apply output to the end. imo i would use cstdio for the "a+" from above.
#11
Re: Getting going in the right direction
Posted 15 June 2009 - 01:18 PM
Kanvus, on 15 Jun, 2009 - 10:10 AM, said:
file.open("whatsfordinnermom.txt",ios::app | ios::out);
that would only allow output and apply output to the end. imo i would use cstdio for the "a+" from above.
but isnt that what he is trying to do?
|
|

New Topic/Question
Reply




MultiQuote




|