So I'm working on something for my dad's company, the general idea is that we download sale data into an excel pivot table, we then export that data (via a csv file) to a program which will account for some variables and fill in some blanks(like if we hadn't sold any cars of a certain kind that week, etc) then it sends the info to a csv file to be opened in excel and uploaded to one of our suppliers website to tell them how much we are willing to pay for which kind of vehicle, so far, I've written (with MUCH online help) a program that sorts out the CSV file by both row and individual value and prints it out, the problem I've run into now, is i need a way to save these values in an easy to manage and easy to edit way, I was thinking an array but if I need to edit a specific vehicle type i feel like it'd be impossible to find within the array, what i need is some way to use the info within the csv file to automatically assign names to int value representing how much we're willing to pay, based on the name of the car(so a 2004 ford mustang would be something like int FordMustand2004) is there any way to do this short of making an array for each line and naming it by hand? I've literally started learning C++ on my own(with the help of a book) for only about a week or so now, so thanks in advance for any help!
#include <iterator>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
usingnamespace std;
int main () {
ifstream file ( "Stuff.csv" ); // declare file stream:
string line; //the entire line WITH commas
stringstream iss; //the stringstream to parse the line for commas
string value; //individual values
while ( getline(file, line) ) //read entire line
{
iss << line; //create istringstream for parsing
while ( getline(iss, value, ',') ) //parse for commas
{
cout << value<< " "; // print each value without commas
}
iss.clear();
cout << "\n"; // create new line for next vehicle
}
cout << "\n Press ENTER to continue...";
cin.ignore(numeric_limits<streamsize>::max(), '\n' );
return 0;
}
heres an example of one line of the output
1 2
Condition Make Year Range Vehicle Type Model Bid
Static Volkswagen 2000-2005 Passenger Car Passat 1350
It really seems like this would be much easier in a database program such as Microsoft Access. You can import and export CSV files easily. Once the data is in a DB table, you can filter, sort and update the data easily.
If you really want to do this in C++, then I suggest you look at some of the STL containers such as std::map. You will want to create a struct or a class to hold the data for each car, then you'll want to create one or more containers allowing you to navigate through the data.
If I'm understanding you correctly, you could make a map that maps string (names) to values (pay amount) so you don't need to come up with integer indexes into an array for each name. Is that what you're looking for?
I'm looking into whether or not access is sufficient for what we need at the moment, and it would need to be very specific, like pretty much include every value except the bid in the name, can it do that? or just one of the values?
I find Access very powerful for the kind of problem you're describing.
It's very easy to create custom forms that can filter, sort and display the data any way you want. You can even use Visual Basic if you need some customization.
Feel free to IM me with a better description of what you're trying to do.