Check the code!!

Please support our C++ advertiser: Intel Parallel Studio Home
Closed Thread

Join Date: Apr 2005
Posts: 9
Reputation: Rose Aashii is an unknown quantity at this point 
Solved Threads: 0
Rose Aashii Rose Aashii is offline Offline
Newbie Poster

Check the code!!

 
0
  #1
May 2nd, 2005
Hye.
i write this code to get inpur from user such as ram and hard disk capacity as integer type using structures. After that i want to create a file in which i want to save that data. In the code below it is getting input from user but not creating file. Plz tell where is my mistake.
Code is:

#include <conio.h>
#include <iostream.h>
#include <fstream.h>

void main()
{
struct computerspec
{
int ram;
int hdisk;
}compuspec;

cout<<"Enter the RAM capacity"<<endl;
cin>>compuspec.ram;


cout<<endl;
cout<<"Enter the Hard Disk capacity"<<endl;
cin>>compuspec.hdisk;


cout<<endl;

ofstream file;

file.open("computerspec.txt");

file<<"ComputerSpec attributes/Data members\n";

file<<"RAM: "<<compuspec.ram<<endl;

file<<"Hdisk: "<<compuspec.hdisk<<endl;

file.close();

getch();

}
Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: Check the code!!

 
0
  #2
May 2nd, 2005
file.open("computerspec.txt");

You need to check if the file is open so
  1. if (file.fail())
  2. {
  3. cerr<<"error opening file"<<endl;
  4. exit(1);
  5. }
  6. else
  7. cout << "File opened for processing" <<endl;

the chances are you havent created that file on the hdd or even if you have it may be in the wrong directory
Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

Re: Check the code!!

 
0
  #3
May 2nd, 2005
Code tags please. http://daniweb.com/techtalkforums/announcement8-3.html.
Also it is int main not void main.
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Check the code!!

 
0
  #4
May 5th, 2005
Thread closed. Please don't double-post.
Alex Cavnar, aka alc6379
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC