the basic idea is that i have a config file where i need to take entries in different formats(the key is always a string and the value could be any type: int, float, string etc) from and the file has the following style:
firstentry 1.5
secondentry 35
thirdentry somestring
and i have this code to try to read int values from the entries but it gives me a lot of errors:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <map>
#include <Windows.h>
using namespace std;
map<string, stringstream> entries;
int ReadInt(const string& key)
{
int value;
stringstream SS;
for(auto i = entries.begin( ); i != entries.end( ); i++)
{
if(i->first == key)
{
SS = i->second;
SS >> value;
return value;
}
}
// throw "Value not found";
return 0;
}
int main( )
{
ifstream file("abc.txt");
string line, key;
while(getline(file, line))
{
cout << "reading line..." << endl;
stringstream SS(line);
SS >> key;
entries[key] = SS;
}
int x = ReadInt("firstentry");
int y = ReadInt("secondentry");
cout << x << " " << y << endl;
system("pause");
return 0;
}
errors:
1>------ Build started: Project: abc, Configuration: Debug Win32 ------
1> main.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(860): error C2249: 'std::basic_ios<_Elem,_Traits>::operator =' : no accessible path to private member declared in virtual base 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ios(177) : see declaration of 'std::basic_ios<_Elem,_Traits>::operator ='
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator =(const std::basic_istream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(604): error C2249: 'std::basic_ios<_Elem,_Traits>::operator =' : no accessible path to private member declared in virtual base 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ios(177) : see declaration of 'std::basic_ios<_Elem,_Traits>::operator ='
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator =(const std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
anybody knows what's the problem? seems fine to me