Covert Java to C++

Can someone please help convert the following code to C++.
I am trying to read a csv file and parse it into columns.
Thanks
import java.io.*;
import java.util.*;

public class CsvSum{

static Map<String, Integer> map = new HashMap<String, Integer>();

public static void main(String args[]) throws Exception{
File file = new File("test.csv");
Scanner scanner = new Scanner(file);
while(scanner.hasNext()){
String line = scanner.next();
String[] columns = line.split(";");

String date = columns[0].replace("DATE=","");
String id = columns[1].replace("ID=","");
int avg = Integer.parseInt(columns[2].replace("AVG=",""));

String key = date + "_" +id;
if(!map.containsKey(key)){
map.put(key,avg);
}else{
Integer existing = map.get(key);
map.put(key, existing + avg);
}
}

System.out.println(map);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <unordered_map>
#include <fstream>
#include <string>

using umap = std::unordered_map<std::string, int>;
int main() {
    umap map;
    std::ifstream file("test.csv");

    std::string line;
    while (file >> line) {
        ...
    }
    return 0;
}


Useful links:
std::string::replace - http://www.cplusplus.com/reference/string/string/replace/
std::stoi - http://www.cplusplus.com/reference/string/stoi/
http://stackoverflow.com/questions/236129/split-a-string-in-c
Topic archived. No new replies allowed.