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.










share|improve this question















marked as duplicate by NathanOliver c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

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















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.










share|improve this question















marked as duplicate by NathanOliver c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

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













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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

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 c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

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


















  • 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












1 Answer
1






active

oldest

votes

















up vote
0
down vote














  1. Read the first line.


  2. Split on , using something like strtok().


  3. Add each of the resulting substrings into your row vector.


  4. Add the row vector to your main vector.


  5. 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.






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote














    1. Read the first line.


    2. Split on , using something like strtok().


    3. Add each of the resulting substrings into your row vector.


    4. Add the row vector to your main vector.


    5. 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.






    share|improve this answer

























      up vote
      0
      down vote














      1. Read the first line.


      2. Split on , using something like strtok().


      3. Add each of the resulting substrings into your row vector.


      4. Add the row vector to your main vector.


      5. 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.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote










        1. Read the first line.


        2. Split on , using something like strtok().


        3. Add each of the resulting substrings into your row vector.


        4. Add the row vector to your main vector.


        5. 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.






        share|improve this answer













        1. Read the first line.


        2. Split on , using something like strtok().


        3. Add each of the resulting substrings into your row vector.


        4. Add the row vector to your main vector.


        5. 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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 15:36









        dandan78

        9,77995068




        9,77995068















            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'