How to read an M x N matrix from a CSV file [duplicate]
up vote
0
down vote
favorite
This question already has an answer here:
How can I read and parse CSV files in C++?
31 answers
I have the task of reading an M x N matrix of numbers from a CSV file in C++. I have an idea of how to do this using std::vector
(using a vector of vectors is my initial plan); however, I'm having trouble thinking of a way to read in the arbitrary number of columns. Is there an easy way to do this?
My initial plan is to read it line by line and manually find the commas separating the numbers, but again, there could be an arbitrary amount of them.
c++ matrix
marked as duplicate by NathanOliver
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 15:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
This question already has an answer here:
How can I read and parse CSV files in C++?
31 answers
I have the task of reading an M x N matrix of numbers from a CSV file in C++. I have an idea of how to do this using std::vector
(using a vector of vectors is my initial plan); however, I'm having trouble thinking of a way to read in the arbitrary number of columns. Is there an easy way to do this?
My initial plan is to read it line by line and manually find the commas separating the numbers, but again, there could be an arbitrary amount of them.
c++ matrix
marked as duplicate by NathanOliver
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 15:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Have a look at Fast CSV Parser if you are allowed to use an external library
– Hristijan Gjorshevski
Nov 19 at 15:25
You should first determine/explain how data are ranged in the file
– Damien
Nov 19 at 15:37
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
How can I read and parse CSV files in C++?
31 answers
I have the task of reading an M x N matrix of numbers from a CSV file in C++. I have an idea of how to do this using std::vector
(using a vector of vectors is my initial plan); however, I'm having trouble thinking of a way to read in the arbitrary number of columns. Is there an easy way to do this?
My initial plan is to read it line by line and manually find the commas separating the numbers, but again, there could be an arbitrary amount of them.
c++ matrix
This question already has an answer here:
How can I read and parse CSV files in C++?
31 answers
I have the task of reading an M x N matrix of numbers from a CSV file in C++. I have an idea of how to do this using std::vector
(using a vector of vectors is my initial plan); however, I'm having trouble thinking of a way to read in the arbitrary number of columns. Is there an easy way to do this?
My initial plan is to read it line by line and manually find the commas separating the numbers, but again, there could be an arbitrary amount of them.
This question already has an answer here:
How can I read and parse CSV files in C++?
31 answers
c++ matrix
c++ matrix
edited Nov 19 at 15:24
dandan78
9,77995068
9,77995068
asked Nov 19 at 15:19
Zcomp
1
1
marked as duplicate by NathanOliver
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 15:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by NathanOliver
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 15:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Have a look at Fast CSV Parser if you are allowed to use an external library
– Hristijan Gjorshevski
Nov 19 at 15:25
You should first determine/explain how data are ranged in the file
– Damien
Nov 19 at 15:37
add a comment |
Have a look at Fast CSV Parser if you are allowed to use an external library
– Hristijan Gjorshevski
Nov 19 at 15:25
You should first determine/explain how data are ranged in the file
– Damien
Nov 19 at 15:37
Have a look at Fast CSV Parser if you are allowed to use an external library
– Hristijan Gjorshevski
Nov 19 at 15:25
Have a look at Fast CSV Parser if you are allowed to use an external library
– Hristijan Gjorshevski
Nov 19 at 15:25
You should first determine/explain how data are ranged in the file
– Damien
Nov 19 at 15:37
You should first determine/explain how data are ranged in the file
– Damien
Nov 19 at 15:37
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Read the first line.
Split on
,
using something likestrtok()
.Add each of the resulting substrings into your row vector.
Add the row vector to your main vector.
Repeat until all the rows in the CSV file have been processed.
Since vector
handles its own memory and can contain an arbitrary number of items, you should be good to go.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Read the first line.
Split on
,
using something likestrtok()
.Add each of the resulting substrings into your row vector.
Add the row vector to your main vector.
Repeat until all the rows in the CSV file have been processed.
Since vector
handles its own memory and can contain an arbitrary number of items, you should be good to go.
add a comment |
up vote
0
down vote
Read the first line.
Split on
,
using something likestrtok()
.Add each of the resulting substrings into your row vector.
Add the row vector to your main vector.
Repeat until all the rows in the CSV file have been processed.
Since vector
handles its own memory and can contain an arbitrary number of items, you should be good to go.
add a comment |
up vote
0
down vote
up vote
0
down vote
Read the first line.
Split on
,
using something likestrtok()
.Add each of the resulting substrings into your row vector.
Add the row vector to your main vector.
Repeat until all the rows in the CSV file have been processed.
Since vector
handles its own memory and can contain an arbitrary number of items, you should be good to go.
Read the first line.
Split on
,
using something likestrtok()
.Add each of the resulting substrings into your row vector.
Add the row vector to your main vector.
Repeat until all the rows in the CSV file have been processed.
Since vector
handles its own memory and can contain an arbitrary number of items, you should be good to go.
answered Nov 19 at 15:36
dandan78
9,77995068
9,77995068
add a comment |
add a comment |
Have a look at Fast CSV Parser if you are allowed to use an external library
– Hristijan Gjorshevski
Nov 19 at 15:25
You should first determine/explain how data are ranged in the file
– Damien
Nov 19 at 15:37