954,193 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

File Mainipulation

I am extremely new to C++ and I've been trying to do a few things.

I want to read a file and get all the numeric values. This information is going to be used in writing a binary file. I also want to count how many numeric values where found.

Next I want to create a binary file and use each of the seperate numeric values to insert the value into a binary string at a exact offset.

So something like this number.txt includes
1 - blah
2 - blah blah
3 - blah blah blah

program then takes the numbers out
1,2,3

then writes at offset 150 a list of numbers already pre-determined and puts first number found from the number.txt into the offset that is also predetermined and just repeats this process all the way through every number.

1- (offset 150 start here)010101001(insert here offset 10 insert numeric value here)01010

2- (offset 150 start here)010101001(insert here offset 10 insert numeric value here)01010

3- (offset 150 start here)010101001(insert here offset 10 insert numeric value here)01010

Any help is appreciated.

Phruis
Newbie Poster
3 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

Announcement: We only give homework help to those who show effort

Take a stab at writing some code.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

Is what I have for reading and displaying the file but I dont know how to extract the numbers. I know I could place them in some kind of array I just cant find the command.

[PHP]
int readnumber(){

fstream infile;
infile.open (path, fstream::in);

while (infile.good())
cout << (char) infile.get();

infile.close();


return 0;

}[/PHP]

Phruis
Newbie Poster
3 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

Sorry for the double post but ive been looking through functions and websites trying to figure out something I could just ask somebody else.

http://publib.boulder.ibm.com/infocenter/tpfhelp/current/index.jsp?topic=/com.ibm.tpf.doc_put.20/gtpc2/gtpc2m02.htm

Phruis
Newbie Poster
3 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

Perhaps read the input file a line at a time using a string and getline . Then parse the line of text: you could use stringstream s, but I might go with sscanf .

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You