#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
int main ()
{
string dBTLine;
string split;
stringstream ss;
int n = 1;
struct subscriber
{
string fName;
string lName;
string company;
}
vector<subscriber> sub;
ifstream dBT ("test.txt");
if (dBT.is_open())
{
getline (dBT,dBTLine);
while ( dBT.good() )
{
system("PAUSE"); //Just to make sure I'm paying attention when it executes
for ( int y = 0; y < 20; y++ )
{
string subscriber;
for ( int x = 0; x < 50; x++ )
{
getline(dBT, split, '|');
cout << split << endl;
switch (x)
{
case 0:
cout << split << " inside case 0" << endl;
sub[0].fName.push_back(split);
cout << sub[0].fName<< endl;
system("PAUSE");
break;
case 1:
cout << split << " inside case 1" << endl;
sub[0].lName.push_back(split);
cout << sub[0].lName<< endl;
system("PAUSE");
break;
case 2:
cout << split << " inside case 2" << endl;
sub[0].company.push_back(split);
cout << sub[0].company<< endl;
system("PAUSE");
break;
}
dailyBundleTop.close();
}
}
}
}
else cout << "Unable to open file";
return 0;
}
So I've been trying many different ways to get the info in the file to the vector of structures. The I get is for the 2nd line of the cases:
error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::push_back' : cannot convert parameter 1 from 'std::string' to 'char'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I've been teaching myself C++ and am pretty new to it. From what I can understand, using push_back, I need to have a char in the () instead of a string. Should I have the struct use char instead of string for these variables? I tried using char, but haven't been able to find a way to convert the string to char to input. I've seen people directly enter "..." strings, but the only way I am able to is to have it already inside a variable and then try to get it into the vector of structs.

New Topic/Question
Reply



MultiQuote






|