473,394 Members | 1,845 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,394 software developers and data experts.

fstream Help

Ive been working on a program that will take a text document that contains a list of words and put them into individual array slots. This is what i have so far.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <iostream.h>
  4. #include <iomanip.h>
  5. #include <fstream.h>
  6. #include "string"
  7. int main(int argc, char *argv[])
  8. {  string data;
  9.  
  10.   ifstream in_file1;
  11.   in_file1.open("wordlist.txt");
  12.  
  13.  
  14.   in_file1>>data;
  15.  
  16.   cout<<data <<endl;
  17.  
  18.       system("PAUSE");
  19.       return 0;
  20. }
  21.  
  22.  


I am rather new to programming and I am a little stumped and i havent found much on the internet so any help would be greatly apreciated. I am trying to figure out how to load the wordlist into the program.
Jul 1 '07 #1
1 1215
Ive been working on a program that will take a text document that contains a list of words and put them into individual array slots. This is what i have so far.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <iostream.h>
  4. #include <iomanip.h>
  5. #include <fstream.h>
  6. #include "string"
  7. int main(int argc, char *argv[])
  8. {  string data;
  9.  
  10.   ifstream in_file1;
  11.   in_file1.open("wordlist.txt");
  12.  
  13.  
  14.   in_file1>>data;
  15.  
  16.   cout<<data <<endl;
  17.  
  18.       system("PAUSE");
  19.       return 0;
  20. }
  21.  
  22.  


I am rather new to programming and I am a little stumped and i havent found much on the internet so any help would be greatly apreciated. I am trying to figure out how to load the wordlist into the program.
If you just want to put each individual word into the next element in an array, then first you'll need to change your string variable data into a string array, and you'll need to know how many words it will be. I'll assume 10, but it could be made larger:

then all you do is use a while loop to loop until you reach the end of the array or the end of the file, and read each word into the next array slot:

Expand|Select|Wrap|Line Numbers
  1. string data[10];
  2. int i = 0;
  3.  
  4. while (i < 10 && !in_file1.eof())
  5. {
  6.     in_file1 >> data[i];
  7.     i = i + 1;
  8. }
Jul 2 '07 #2

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

Similar topics

2
by: Maya | last post by:
Apart from being a pointer, what would be the benefit of using 'std::filebuf' than using the std::fstream? As far as I can see, I would use the same methods in 'filebuf' that I would when using...
8
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out |...
6
by: Armando | last post by:
Hallo ! I habe some error in my programm,because i use <fstream.h>,I want to use <fstream> but i donīt know which fonctions i must modify in my program ? Thanks you for your help. Armando.
14
by: Mike - EMAIL IGNORED | last post by:
Using RH9, from this fragment: fstream theStream_; string fPath = "myFile"; int mode = O_EXCL | O_CREAT; theStream_.open(fPath.c_str(),mode); I get the failure shown below. ...
7
by: Christian Henke | last post by:
Hi! maybe someone can help me?! I want to use fstream to read an .au file . This .au file includes multiple information in its header. a MagicNumber, the No of Channels used, and so on. In...
3
by: ratzeel | last post by:
The following snippet code throws an error while compiling on SUN os.. Any idea how to resolve this... #include <iostream.h> #include <fstream.h> #include <math.h> #include <algorithm>...
9
by: Someonekicked | last post by:
In my program, I need to open multiple files, and I wont know till after the program execution how many of them (user will enter that value). So I am using a vector of fstream. I am using fstream...
6
by: wiso | last post by:
My problem is this (from: http://www.cplusplus.com/ref/iostream/fstream/open.html) #include <fstream> using namespace std; int main() { fstream f;
2
by: jjcp | last post by:
I would like to say thanks in advance for insight anyone can shed on this for me. Long story short from time to time I need to us C++ to take a list of file and make an index out of them in...
7
by: Soneji | last post by:
*sigh* Ok, I have two questions. First, my setup: Win-doze XP-SP2; & Dev-C++ 4.9.9.2; I recently started trying to use 'fstream' to work my input/output, and I noticed that using the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.