By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

A few questions about files..

P: 11
Well, i still don't understand some things about files...
For example, i have created a file, with following structure ->
int,int,float, some class, some other class....
And, i open that file to read, and i want to load only the some_class. So, how can i "skip" the other unneded variables? I have looked for it in Jesse Liberty's "Teach yourself c++ in 21 days.", but i didn't understand, as i haven't understood the online tutorials in that matter....
And three more questions:
1) How to copy a file / folder with files to another directory?
2) How to rename the file / folder?
3) How to delete the file / folder?
Feb 21 '07 #1
Share this Question
Share on Google+
8 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
Well, i still don't understand some things about files...
For example, i have created a file, with following structure ->
int,int,float, some class, some other class....
And, i open that file to read, and i want to load only the some_class. So, how can i "skip" the other unneded variables? I have looked for it in Jesse Liberty's "Teach yourself c++ in 21 days.", but i didn't understand, as i haven't understood the online tutorials in that matter....
And three more questions:
1) How to copy a file / folder with files to another directory?
2) How to rename the file / folder?
3) How to delete the file / folder?
To answer your first (in the written, non-numbered portion) question, how much do you know about reading input in from a file? (Why not just read them in and forget about them?)

For 1,2&3 - what OS are you on, and what have you tried?
Feb 21 '07 #2

RedSon
Expert 5K+
P: 5,000
What are you trying to do? You want to open a .cpp file and skip everything until you get to a particular class then read in that class? Your question is very confusing.
Feb 21 '07 #3

P: 11
Sorry if my post caused "confusion", but the file is a .txt.
Sicarie ->
Not much, only creating and reading the file, writing into file and reading out of file in specified "order". And I'm using dev-cpp, under windows XP.
Feb 21 '07 #4

sicarie
Expert Mod 2.5K+
P: 4,677
Sorry if my post caused "confusion", but the file is a .txt.
Sicarie ->
Not much, only creating and reading the file, writing into file and reading out of file in specified "order". And I'm using dev-cpp, under windows XP.
Then you should just need the 'system()' command with whatever dos command does those things.
Feb 22 '07 #5

P: 11
Then you should just need the 'system()' command with whatever dos command does those things.
Thanks for this, Sicarie :D.
Yet, there are some other questions....
Is there any other way to delete/rename than using system commands?

And, could you explain to me, how to read only specified part of the file (that's the first question i have asked :) ), if i want to get only one thing from the file?
Feb 23 '07 #6

sicarie
Expert Mod 2.5K+
P: 4,677
Thanks for this, Sicarie :D.
Yet, there are some other questions....
Is there any other way to delete/rename than using system commands?
Not sure, but probably - that would be a good (and probably pretty easy) thing to google search.

And, could you explain to me, how to read only specified part of the file (that's the first question i have asked :) ), if i want to get only one thing from the file?
Yeah, if you knew exactly what was there, you could read in until you hit

class ClassName

and then copy the lines to wherever you wanted them. I would initially set it up to match '{'s. I don't think you would have full matching '{'s unless the class was completed.
Feb 23 '07 #7

P: 11
I'm still a newbie, so could you please make a sample code? I can only read things from file using
Expand|Select|Wrap|Line Numbers
  1.  File.read((char*) &b, sizeof(b));
. I don't know well how to read using a line. Also, i have noticed, that if i put
Expand|Select|Wrap|Line Numbers
  1. file << " ";
into code that writes something to file, i am unable to skip it, so it is impossible to read anything that is behind. So, how to skip those fragments?a
Feb 23 '07 #8

sicarie
Expert Mod 2.5K+
P: 4,677
I'm still a newbie, so could you please make a sample code? I can only read things from file using
Expand|Select|Wrap|Line Numbers
  1.  File.read((char*) &b, sizeof(b));
. I don't know well how to read using a line. Also, i have noticed, that if i put
Expand|Select|Wrap|Line Numbers
  1. file << " ";
into code that writes something to file, i am unable to skip it, so it is impossible to read anything that is behind. So, how to skip those fragments?a
Sorry, I can't write the code for you, but I can say that I would recommend using getline(). Let us know if you have trouble with that or another part of the program!
Feb 23 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.