Total members 9950 | Gratitudes |It is currently Sat Feb 11, 2012 1:39 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: C++ File I/O
PostPosted: Sat Mar 28, 2009 3:28 pm 
Offline
Newbie
User avatar

Joined: Sat Mar 28, 2009 3:10 pm
Posts: 1
Has thanked: 0 time
Have thanks: 0 time

Well, it's the weekend, and my program due for class tomorrow isn't finished. The instructor isn't likely going to be available, so I'm hoping someone on here might be able to help out with a problem I'm having. I'll give the general layout of the program I am writing:

We are to pull from a text file the following information, in this format:

New York
0.075 0.06 0.081 0.056
0.065 0.068 0.07 0.059
0.07 0.075 0.068 0.073

The location is of course listed at the top in string format, and all of the individual numbers are ppm readings. The first in each row is a standard, the following three in that row are readings from sensors placed throughout the location. My programs purpose is to pull this information from the file, compare the readings to the standard, decide whether or not each polutant is in compliance with set standards.

Let's say this is in a simple notepad text file laid out as such. I forgot to mention, in my instructions at the end of each row there could be uneeded information, so I would need an ignore line for each row I would guess. This is how I have the first part of my program laid out, and just to test to see if the values are actually being pulled, I stuck in a section of COUT that isn't needed in the final program. Here is what I have :

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()

{

/*For simplicity sake, I am only using the first two rows of variables! These aren't all I will need for the entire program, I am aware of that. Just to show what the problem I'm having is.*/

float ozstd;
float oz1;
float oz2;
float oz3;
float nitstd;
float nit1;
float nit2;
float nit3;
string fileName;

ifstream inFile;

cout << "Please enter the name of the file to be used: ";
cin >> fileName;

inFile.open(fileName.c_str());

/*I'm not really sure how to pull the string name yet either. But this is for the numerical values*/

inFile >> ozstd >> oz1 >> oz2 >> oz3;
inFile >> nitstd >> nit1 >> nit2 >> nit3;

inFile.close();

cout << "TEST to see if values are pulled from file " << ozstd << " " << oz1 << " " << oz2 << " " << oz3 << endl;

return 0;
}

When I compile this, everything runs fine, except for one thing. I get this random string of numbers in my output AND, I can type any filename into the prompt, I will get the same set of numbers in output. Lets say the file name is TEST1.txt That's the exact way I type it in, but I could also type TST1.txt and get the same result. I believe it's just not opening and reading from the file. Any ideas at all would be greatly appreciated! Thanks!


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 How to make PHP form data saved into txt file  PHP  Radu  6
 file exists in upper level folder link  HTML examples  msi_333  0
 How to merge the data into file  Java  Anonymous  1
 How to use xml file to populate listbox  C#  Anonymous  1
 File Permission  PHP  Anonymous  1

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team