Created
December 10, 2024 03:34
-
-
Save abikoushi/b1fc6c0ad8d0765537445d4c4e56d967 to your computer and use it in GitHub Desktop.
get a line from csv (Rcpp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "RcppArmadillo.h" | |
// [[Rcpp::depends(RcppArmadillo)]] | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
std::vector<double> readaline(std::string readtxt, int ind_n) { | |
std::ifstream file(readtxt); | |
std::string str; | |
std::vector<double> result; | |
int index = 0; | |
while (std::getline(file, str)) | |
{ | |
if(index == ind_n){ | |
std::stringstream ss(str); | |
while( ss.good() ) | |
{ | |
std::string substr; | |
getline(ss, substr, ','); | |
result.push_back( stod(substr) ); | |
} | |
} | |
index++; | |
if(index>ind_n){ | |
break; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment