Yesterday I made a small script with some help to read .csv files. Although I found a way to read the first value and save it, but for some reason it saves the last value instead.
I store what I thought should be the first value under value1, and re-display it to make sure it is displayed correctly and is actually stored under the called variable.
Does anyone know what is wrong with this code? I think I should use vectors, but when I read the help sheets that I find on the Internet, I will throw a little about them. Any help is appreciated.
#include <iostream> #include <fstream> #include <string> using namespace std; int main () { int loop = 1; string value; string value1; while(loop = 1) { cout << "Welcome! \n" << endl; ifstream myfile; myfile.open ("C:/Documents and Settings/RHatfield/My Documents/C++/Product Catalog Creator/Source/External/Sample.csv"); while (myfile.good()) getline ( myfile, value, ',' ); cout << string ( value) << endl; value1 = value; cout << value1; myfile.close(); system("PAUSE"); return 0; } }
source share