How to copy the first char of a string to a char?

This is a very simple election program for my c++ class, I need to write the votes on a txt file after that I need to read the file and count the votes and I dont now how...
I dont now how to convet a string to a char to make the count...
Can someone give me a help?

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;

int main ()
{
char can;
char vote;
int c1=0, c2=0, c3=0, c4=0, null=0;
string line;
ofstream fout ("c:/vote.txt");
ifstream fin ("c:/vote.txt");
fout.close();
fin.close();

while (can!='0')
{
system ("cls");
cout << "\n\tChoose on:" << endl;
cout << "\t\t1 - Can 1" << endl;
cout << "\t\t2 - Can 2" << endl;
cout << "\t\t3 - Can 3" << endl;
cout << "\t\t4 - Can 4" << endl;
cout << "\t\t0 - exit." << endl;
cout << "\t\t";

cin >> can;

if (can!='0')
{ fout.open ("c:/vote.txt", ios::app);
fout << can << endl;
fout.close();
}
}

fin.open ("c:/vote.txt");
while (!fin.eof())
{
getline (fin, line);
strcpy (vote, line);
cout << vote << endl;

if (vote = '1')
c1++;
else
if (vote = '2')
c2++;
else
if (vote = '3')
c3++;
else
if (vote = '4')
c4++;
else
null++;

}
fin.close();


system ("cls");
cout << "\n\tTotal: Can 1 " << c1 << "votes." << endl;
cout << "\t Can 2 " << c2 << "votes." << endl;
cout << "\t Can 3 " << c3 << "votes." << endl;
cout << "\t Can 4 " << c4 << "votes." << endl;
cout << "\t Null votes " << null << "." << endl;

system ("pause");
return 0;
}
Get rid of strcpy( vote, line ) and your if()s need to be

if( line.length() == 1 && line[0] == '1' )

etc.
Topic archived. No new replies allowed.