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

how to read tab delim file into 2D Array

I have a tab delimited file, that I want to read into a 2D array. I
want to ignore the first two lines and the first colum of data.
Mar 29 '08 #1
5 5748
yogi_bear_79 wrote:
I have a tab delimited file, that I want to read into a 2D array. I
want to ignore the first two lines and the first colum of data.
I would probably read the line with std::ifstream.getline() using '\n' as delimiter
into a std::string buffer and then split the string using std::stringstream.getline()
using '\t' as delimiter.

sashi
Mar 29 '08 #2
I would probably read the line with std::ifstream.getline() using '\n' as delimiter
into a std::string buffer and then split the string using std::stringstream.getline()
using '\t' as delimiter.

Ok, I can do that, but don't I have to declare the size of the array
before I populate it? I have written the code to figure out how many
rows and columns the text file contains. But I can not figure out a
way to declare the array with non-constant variables?

Mar 29 '08 #3
On Sat, 29 Mar 2008 15:29:59 -0700, yogi_bear_79 wrote:
>I would probably read the line with std::ifstream.getline() using '\n'
as delimiter into a std::string buffer and then split the string using
std::stringstream.getline() using '\t' as delimiter.


Ok, I can do that, but don't I have to declare the size of the array
before I populate it? I have written the code to figure out how many
rows and columns the text file contains. But I can not figure out a way
to declare the array with non-constant variables?
Read about std::vector.

--
OU
Mar 29 '08 #4
yogi_bear_79 wrote:
>I would probably read the line with std::ifstream.getline() using '\n' as delimiter
into a std::string buffer and then split the string using std::stringstream.getline()
using '\t' as delimiter.


Ok, I can do that, but don't I have to declare the size of the array
before I populate it? I have written the code to figure out how many
rows and columns the text file contains. But I can not figure out a
way to declare the array with non-constant variables?
Use std::vector<or similar, so you can add new rows, columns.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
post tenebras lux. post fenestras tux.
Mar 29 '08 #5
>
Read about std::vector.
ok, I Have created a 2D vector, where c=num of columns in my file, and
r=num of rows. I've populated vectors from file before,using a while
loop and pushback, but never a 2D. Below is sample data, basically
the first row is useless, the second row starts with a null, then tab
tehn Exam 1, tab etc.

vector<stringv(c);
vector<vector<string v2(r,v)

This file contains the records of 20 students over 10 exams
Exam1 Exam2 Exam3 Exam4 Exam5 Exam6 Exam7 Exam8 Exam9 Exam10
Student1 90 100 89 75 88 99 100 87 88 85
Student2 99 89 87 89 87 90 87 99 100 95
Mar 29 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Knackeback | last post by:
task: - read/parse CSV file code snippet: string key,line; typedef tokenizer<char_separator<char> > tokenizer; tokenizer tok(string(""), sep); while ( getline(f, line) ){ ++lineNo;...
12
by: Francis Bell | last post by:
Hello, I've got a program that is reading in a data file of 25 lines. Here is an example of the first two lines: sp/spinnerbait/AAA Lures/Mad Phil/silver/bass/1/1 f/floating minnow/AAA...
14
by: spike | last post by:
Im trying to write a program that should read through a binary file searching for the character sequence "\name\" Then it should read the characters following the "\name\" sequence until a NULL...
5
by: Denis Petronenko | last post by:
Hello, how can i read into strings from ifstream? file contains values in following format: value11; val ue12; value 13; valu e21;value22; value23; etc. i need to read like file >string,...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
20
by: czarbjones | last post by:
Hey Gurus, I'm trying to export a query (QueryDataExport) to a comma delim CSV file. The file name should look like this "C:\DSF_20061127_124211.csv" however it is exporting as "C:\DSF_.csv". ...
21
by: cppbeginner | last post by:
Hello, Newbie question: I have a string of nibbles (say 2b11cc4f5db20cd5) that can be put as #define DATA 0x2b11cc4f5db20cd5 or #define DATA "2b11cc4f5db20cd5" Need to read this into...
12
by: macus | last post by:
Dear All, I have 2 cvs file like this: <spec.csv> Type,sybType,ID CASH,ON,1 FRA,1x4,2 ...
3
by: Alex Snast | last post by:
hello guys I need to modify the std::cin delim char from the default ' ' and '\n' characters to ',' i know that i can edit the delim in the getline command however i'd like to know if there's...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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.