There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox firewall freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop malware motherboard mouse network networking outlook outlook 2007 popups power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows xp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Opening files with a twist, C++


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
calculus87's Avatar
Member with 34 posts.
 
Join Date: Sep 2003
26-Sep-2003, 11:03 AM #1
Opening files with a twist, C++
Hello,

Okay, in my program I open a file and begin to put data in the file. Now before I am finished putting the data in the file I need to use some of the data.

okay for example
data in file1:
3 4

Now for the next input I need to take the sum of the first two statements. So the next spot in the statement would be 7

3 4 7

afterwards I go on inputting data.

3 4 7 1 ...

I tried to do a function inside a function, where the outer function opens the file, and begins to input data into it.
Then the inner function is called. It opens the file and takes the
first two inputs, does the conversions, adds them, converts them back then inputs the string into the file then exits.
The outer function then continues inputing into the file.

When I run my code I am supposed to have a=3 and b =4 but they are blank.

so my question is this.
1) can it be done?
2) here is some of the code that I have tried, any suggestions on how to fix this code?

Thanks for the help
~Ronald
//**********************
int main()
{
fstream scan;
scan.open("calcout.txt", ios:ut| ios::in);
output<<"3 ";
output<<"4 ";
output<<getstrings();
output<<"1 "
return 0;
}
//**********************
string getstrings()
{
string a, b;
ifstream input2;
double s1,s2,sum=0;
string t1;
stringstream stream;

input2.open("calcout.txt");
input2>>a;
input2>>b;
cout<<a<<endl<<b<<endl;

s1=atof(a.c_str());
s2=atof(b.c_str());
sum = s1 + s2;

stream << sum;
t1 = stream.str();
input2.close();
return t1;
}
__________________
This message is a natural product made from recycled electrons. The slight
variations in spelling and grammar enhance its individual character and
beauty and in no way are to be considered flaws or defects.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:47 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.