473,320 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Reading and Outputing data from a text file HELP

I am having trouble with a normally simple function, I am trying to read a text file and output what is in the file:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include <fstream> // To access a disk file (both input and output)
  5. #include <string> // To use a sequence of characters
  6. #include "Header.h" 
  7. using namespace std;
  8.  
  9. int main() {
  10.  
  11.    string line;
  12.    ifstream readmatrix ("PE ratios.txt"); //Attempts to locate file and open it
  13.    if (readmatrix.is_open())
  14.    // If the file is found and able to be opened the following will happen:
  15.    {
  16.       while (! readmatrix.eof() )
  17.       {
  18.          getline (readmatrix,line);//reads .txt file
  19.          cout << line << endl; // Prints what is found in.txt file 
  20.       }
  21.  
  22.       readmatrix.close();
  23.       readmatrix.clear();
  24.    }
  25.    return 0;
  26. }




It runs with no errors or warnings, however the files charcters are not outputed when the program is executed.

Does anyone have any ideas of where I have gone wrong as its been a while since I last did c++.
Feb 8 '07 #1
3 1776
Ganon11
3,652 Expert 2GB
Not completely sure. What output are you getting? What does the input file look like?
Feb 8 '07 #2
Dont worry about every1, it was me being stupid, not having the text file saved in the correct direcory!!!!
Feb 8 '07 #3
Tahnks anyway "Ganon11".
Feb 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
4
by: George | last post by:
I am lost on how to do this. I have not worked with C much at all but can understand the basic properties of this language. Could someone please show me or explain to me how to write a function...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
4
by: Gaijinco | last post by:
I had a file named nap.in which looks like this: 4 10:00 12:00 Lectures 12:00 13:00 Lunch, like always. 13:00 15:00 Boring lectures... 15:30 17:45 Reading 4 10:00 12:00 Lectures 12:00 13:00...
1
by: JanaB | last post by:
I am writing a code that needs to read in a binary file. At the moment I don't have to do anything with the data, I just need to view the contents to compare its structure with another binary file....
1
by: une | last post by:
hey guys, I have this program to do, but I kind of started forst just te read things from the file and then I would go and make the calculation but it is showing some wierd funnky resualts, I dont...
11
by: googletired | last post by:
Hello, I've been working on this for a days and getting frustrated. Basically i want read a master xml file that references many other xml files and use this information to output an RSS Feed. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.