So I have a CSV with 2 columns - One for A song and one for the artist of that song. For example
The Pretender,Foo Fighters
In Bloom,Nivana
Champagne Supernova,Oasis
Starlight,Muse
Will We Talk?,Sam Fender
I am converting a python program that I wrote a while back into c++. In that program it uses the csv library to read the csv, and choose a random row from that. It then splits it into two columns and then stores them in variables, answer being the song name and title being the song title:
#select a random row and store it in a list
randomrow = random.choice(list(csvreader))
#print(randomrow)
answer = randomrow[0]
answer = answer.strip()
#print(answer)
track = randomrow[0]
#print(track)
#split track into two columns - title and artist
title = track.split()
I have tried techniques from this thread: here
such as:
#include <sstream>
#include <string>
#include <fstream>
#include <iostream>
std::ifstream songsCsv("Songs.csv");
std::string line;
while (std::getline(songsCsv line))
{
std::istringstream iss(line);
std::string song, artist;
if (!(iss >> song >> artist)) { break; }
cout << song;
cout << artist;
}
however, nothing was outputted here. If anyone had any ideas on how to do this tey would be much appreciated.