The Text file looks like this:
Apple,Itunes,1,7.3
Microsoft,Windows Media Player,1,10
.... and so on.....
The parse method is:
private IApplication parseLineToApp(String lineFromTxtFile) {
Scanner lineScanner = new Scanner(lineFromTxtFile);
lineScanner.useDelimiter(",");
return new Application(lineScanner.next(), lineScanner.next(), lineScanner.nextInt(), lineScanner.next());
}
I want to do the same thing in c++ to create a new application().
Note: I already have an application class, and need to add that application to a repository which is a collection of applications
Thanks in advance :)
解决方案
You can create a vector of strings using Boost and the STL.
// given std::string lineFromTxtFile
std::vector<:string> scanner;
boost::split (scanner, lineFromTxtFile, boost::is_any_of(","));
return new Application (scanner[0], scanner[1], scanner[2], scanner[3]);
If you want scanner[2] to be an integer, there's
boost::lexical_cast (scanner[2])