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

trying to create aan array from a text file

Hi

I am trying to build an array out of an input text file as shown below.

pattern1
SAF 10 1 10
CLB 20 18 10 11

pattern2
SAF 20 1 10 11
SAF 30 1 10
SAF 40 1 11
SAF 10 0 10
SAF 11 0 11

pattern3
SAF 31 1 10
SAF 21 1 11
SAF 10 0 10
SAF 11 0 11

pattern4
SAF 10 1 10
CLB 20 18 10
SAF 21 1 11
SAF 11 0 11

now here the first 3 fields in each line constitute the value field (like value1).Now suppose under heading one there is some value for value1 then it needs to go in the first column. Same way if heading4 has a value for value1 it needs to go under corresponding column4. So the output array should generated would be something like this

[CLB 20 18] [10 11] [ NULL] [ NULL] [ 10]
[SAF 10 0] [ NULL ] [ 10 ] [10 ] [NULL ]
[SAF 10 1 ] [10 ] [NULL ] [ NULL ] [10 ]
[SAF 11 0 ] [NULL ] [11 ] [11] [ 11 ]
[SAF 20 1 ] [NULL ] [10 11 ] [NULL ] [NULL ]
[SAF 21 1 ] [NULL ] [NULL ] [11 ] [11 ]
[SAF 30 1 ] [NULL ] [10 ] [ NULL ] [ NULL ]
[ SAF 31 1 ] [NULL ] [ NULL ] [10 ] [NULL ]
[ SAF 40 1 ] [NULL ] [11 ] [ NULL] [ NULL ]

The square brackets are just to show the whole thing as one string

Now if I read the complete line using getline then I am not able to ignore the lines with word pattern. If I use cin then I get each word individually. I hope I am not making it too complicated. My code so far is:

#include<iostream>
#include<string>
#include <fstream>
using namespace std;

int main(){
ifstream input("detection_report.txt", ios::in);
int columns = 0;

if(!input)
{
cerr<<"File could not be opend\n";
exit(1);
}

string value;
while(getline(input,value)){

string check = value.substr(0,1);
if (check == "p")
{
columns = columns + 1;
}
else{

//Here I want to read the lines without the "pattern" words.
//Secondly I just want to read only the first three groups to put in an array.
//which is quite difficult using a substr as some will need 8 characters and some will need 9.
}
cout << value << "\n";
}

input.close();
cout << "Columns: " << columns <<"\n";

return 0;
}
Nov 16 '06 #1
0 1186

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

Similar topics

8
by: ASP Yaboh | last post by:
I have an ArrayList of data gathered from a database. I want to create a web page from this data by creating a <table>, each cell in each row displays the appropriate data. One of those cells in...
2
by: monkeyinquisition | last post by:
Hi All, I'm trying to read data from a text file into an array. The text file (a test) looks like this: 1 2 3 4 5 6 7 8
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
by: | last post by:
Hi all, I want to create a method that does the following: 1) Programmatically instantiate a new XmlDataSource control 2) For each file in a named directory, make a "FileSystemItem" element 3)...
4
by: sirjohnofthewest | last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man. Hi guys, I frequently visit this site to get answers to my...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
3
by: gsuns82 | last post by:
HI all, I tried to read an array from an external javascript file called read.js,The array was declared & as well as defined with some values inside the <script> tag of a html file. For an...
7
by: jeddiki | last post by:
Hi, As I am in Turkey at present, I can not see vidoes on youtube. So I have tried a few proxies but keep finding them slow or not working. So I have installed myphpProxy on my server under...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.