error C2228: left of '.swap' must have class/struct/union type

I have added another vector in order to keep track of all the lengths of each name. I am having some trouble with the sorting part of it. Can someone please help resolve this error.

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <vector>
using namespace std;
int main()
{
string fileName,line;
ifstream infile;
cout<<"Enter the file name and complete path: ";
cin>>fileName;
int Aa=0,count=0;
std::vector<string> A_names;
std::vector<int> A_names_sizes;
infile.open(fileName.c_str());
while(!infile.eof())
{
getline(infile,line);
if(line[count]=='A'||line[count]=='a')
{
A_names.push_back(line);
A_names_sizes.push_back(strlen(line.c_str()));
A_names[Aa]=line;
A_names_sizes[Aa]=strlen(line.c_str());
Aa++;
const size_t size = A_names.size();
for(size_t i=0; i<size; ++i)
{
for (size_t j=0; j<size-i-1;j++)
{
if (A_names[j+1].length() < A_names[j].length())// ascending order simply changes to <
{
A_names[j].swap(A_names[j+1]);
}
if (A_names_sizes[j+1] < A_names_sizes[j])// ascending order simply changes to <
{
A_names_sizes[j].swap(A_names_sizes[j+1]);//PROBLEM IS HERE
}
}
}
}
}
return 0;
}
Last edited on
int does not have a swap member function. Use swap(A_names_sizes[j], A_names_sizes[j+1]); instead.
What exactly is the point of A_names_sizes? std::string already hold the string's size.
Topic archived. No new replies allowed.