LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2010, 10:32 PM   #1
golfgirl32
LQ Newbie
 
Registered: Oct 2010
Posts: 6

Rep: Reputation: 0
Reading a File into an Array


I know that this is a really simple thing to do but I just can't figure it out. How do I read a text file into an array in C++? Help would be appreciated
 
Old 10-20-2010, 11:20 PM   #2
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: RHEL/Ubuntu/Debian/Fedora/Centos/K3OS
Posts: 1,159
Blog Entries: 4

Rep: Reputation: 149Reputation: 149
Hi,

Hope this link helps you:

http://forums.techguy.org/software-d...nto-array.html
 
Old 10-20-2010, 11:41 PM   #3
golfgirl32
LQ Newbie
 
Registered: Oct 2010
Posts: 6

Original Poster
Rep: Reputation: 0
No that confused me even more. Should I just declare the array and then afterward make sure the file opens?
 
Old 10-20-2010, 11:43 PM   #4
golfgirl32
LQ Newbie
 
Registered: Oct 2010
Posts: 6

Original Poster
Rep: Reputation: 0
This is the program I have so far...

Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>

using namespace std;

// Function prototypes (ensure you add the comments)

int main()
{
    ifstream input;

    input.open("numbers.txt");
    if (input.fail())
    {
        cout<<"Input file opening failed.\n";
        exit(1);
    }


    return 0;

    input.close();
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Reading numbers from text file and storing in array idaham Linux - General 3 05-27-2010 03:36 AM
Bash - Reading csv delimited file to array and for further manipulation BLWEGRZYN Programming 1 01-06-2010 09:38 PM
Reading an array from another file nobody123 Linux - Newbie 14 03-21-2009 02:45 PM
Java - reading from a file into an array joegumbo Programming 9 09-29-2008 05:12 PM
Reading from a txt file into a two dimension array in C kponenation Programming 3 11-26-2005 07:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration