| | |
Check the code!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 9
Reputation:
Solved Threads: 0
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();
}
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();
}
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
file.open("computerspec.txt");
You need to check if the file is open so
the chances are you havent created that file on the hdd or even if you have it may be in the wrong directory
You need to check if the file is open so
C++ Syntax (Toggle Plain Text)
if (file.fail()) { cerr<<"error opening file"<<endl; exit(1); } else 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
•
•
Join Date: Nov 2004
Posts: 108
Reputation:
Solved Threads: 3
Code tags please. http://daniweb.com/techtalkforums/announcement8-3.html.
Also it is int main not void main.
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.
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
![]() |
Similar Threads
- exit code error (C++)
- Time check problem (C++)
- Quality check (C++)
- check for errors in my code (C++)
- QBasic Nested for loop (Legacy and Other Languages)
- Circle class (C++)
- banner ad's here? (Advertising Sales Strategies)
Other Threads in the C++ Forum
- Previous Thread: problem with fstream
- Next Thread: Unix - The make tool
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





