Not sure why errors are thrown

I'm not sure why my code is getting errors, any help in figuring out why, and how to fix would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
 
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;
int main()
{

{
    string pirates[5];    //array holding rows
    short loop;           //short loop for input
    short loop2;          //short loop for output
    string line;          //file data
    ifstream myfile ("input.txt");    //open the file.
    if (myfile.is_open())             //checks if the file is open
  {
    while (! myfile.eof() )           //while the end of file is NOT reached
    {
      getline (myfile,line);          //get one line from the file at a time
      cout << line <<  endl;          //and output it


}
  }
}

void checkdup ();
void createarray ();
    int mymap;    //Open file again

     string pirates[5];  // array to hold names
  short loop;            //short for loop for input
  short loop2;           //short for loop for output
  string line;           //contains the data read from the file
  ifstream myfile ("input.txt");   //open the file.
  if (myfile.is_open())            //if the file is open
  {
    while (! myfile.eof() )        //while the end of file is NOT reached
    {
      getline (myfile,line);       //get one line from the file
      cout << line <<  endl;       //Check for Duplicates

{
    fstream myfile;
    myfile.open("input.txt",ios::in);

    fstream outfile;
    outfile.open("counted .txt",ios::out|ios::app);
    std:map <string, int> mymap;
    string cur;
    while(getline(myfile,cur)){
        if(0==mymap[cur])
    {

            mymap[cur]=1;
            outfile.write(cur.c_str(),cur.length());
            outfile.put('\n');
    }
        else
            mymap[cur]++;
}

{
cout <<"Here is the original data for the pirate votes, including duplicates."<<endl;
createarray();
cout << "This is the file without duplicates"<<endl;
checkdup ();

int uniqueVotes;

std::string ID (uniqueVotes, " ");
    void remove_duplicate()   //this function removes the duplicate IDs

{

ifstream myfile("counted.txt");
string ID[uniqueVotes] = {};
int size = sizeof(ID) / sizeof(string);

string temp = "";
for (int i = 0; i < size; i++)
{
temp = ID[i];
for (int j = i + 1; j < size; j++)
{
if (temp == ID[j])
currentID[j] = "";
}
}

for (int i = 0; i < size; i++)
{
cout << ID[i] << endl;
}
}
This file contains functions that don't even exist...

1
2
void checkdup ();
void createarray ();


I would re-write this if I were you.
Hi,

Don't loop on eof, loop on getline like you do on line 56.

Always initialise your variables, preferably at declaration.

Read the documentation for the things you use.

Don't name functions the same as variables.

Yep, lots of errors:

In function 'int main()': 16:11: warning: unused variable 'loop' [-Wunused-variable] 17:11: warning: unused variable 'loop2' [-Wunused-variable] 76:33: error: no matching function for call to 'std::basic_string<char>::basic_string(int&, const char [2])' 76:33: note: candidates are: In file included from /usr/include/c++/4.9/string:52:0, from /usr/include/c++/4.9/bits/locale_classes.h:40, from /usr/include/c++/4.9/bits/ios_base.h:41, from /usr/include/c++/4.9/ios:42, from /usr/include/c++/4.9/ostream:38, from /usr/include/c++/4.9/iostream:39, from 2: /usr/include/c++/4.9/bits/basic_string.h:540:9: note: template<class _InputIterator> std::basic_string<_CharT, _Traits, _Alloc>::basic_string(_InputIterator, _InputIterator, const _Alloc&) basic_string(_InputIterator __beg, _InputIterator __end, ^ /usr/include/c++/4.9/bits/basic_string.h:540:9: note: template argument deduction/substitution failed: 76:33: note: deduced conflicting types for parameter '_InputIterator' ('int' and 'const char*') In file included from /usr/include/c++/4.9/string:52:0, from /usr/include/c++/4.9/bits/locale_classes.h:40, from /usr/include/c++/4.9/bits/ios_base.h:41, from /usr/include/c++/4.9/ios:42, from /usr/include/c++/4.9/ostream:38, from /usr/include/c++/4.9/iostream:39, from 2: /usr/include/c++/4.9/bits/basic_string.h:530:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::initializer_list<_Tp>, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()); ^ /usr/include/c++/4.9/bits/basic_string.h:530:7: note: no known conversion for argument 1 from 'int' to 'std::initializer_list<char>' /usr/include/c++/4.9/bits/basic_string.h:512:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] basic_string(basic_string&& __str) ^ /usr/include/c++/4.9/bits/basic_string.h:512:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/4.9/bits/basic_string.h:502:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int] <near match> basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()); ^ /usr/include/c++/4.9/bits/basic_string.h:502:7: note: no known conversion for argument 2 from 'const char [2]' to 'char' /usr/include/c++/4.9/bits/basic_string.h:495:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()); ^ /usr/include/c++/4.9/bits/basic_string.h:495:7: note: no known conversion for argument 2 from 'const char [2]' to 'const std::allocator<char>&' /usr/include/c++/4.9/bits/basic_string.h:488:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int] <near match> basic_string(const _CharT* __s, size_type __n, ^ /usr/include/c++/4.9/bits/basic_string.h:488:7: note: no known conversion for argument 2 from 'const char [2]' to 'std::basic_string<char>::size_type {aka long unsigned int}' /usr/include/c++/4.9/bits/basic_string.h:476:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&, std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int] basic_string(const basic_string& __str, size_type __pos, ^ /usr/include/c++/4.9/bits/basic_string.h:476:7: note: candidate expects 4 arguments, 2 provided /usr/include/c++/4.9/bits/basic_string.h:467:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&, std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int] basic_string(const basic_string& __str, size_type __pos, ^ /usr/include/c++/4.9/bits/basic_string.h:467:7: note: no known conversion for argument 1 from 'int' to 'const std::basic_string<char>&' /usr/include/c++/4.9/bits/basic_string.h:460:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] basic_string(const basic_string& __str); ^ /usr/include/c++/4.9/bits/basic_string.h:460:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/4.9/bits/basic_string.h:453:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] basic_string(const _Alloc& __a); ^ /usr/include/c++/4.9/bits/basic_string.h:453:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/4.9/bits/basic_string.h:442:7: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] basic_string() ^ /usr/include/c++/4.9/bits/basic_string.h:442:7: note: candidate expects 0 arguments, 2 provided 79:1: error: a function-definition is not allowed here before '{' token 100:1: error: expected '}' at end of input 100:1: error: expected '}' at end of input 100:1: error: expected '}' at end of input 100:1: error: expected '}' at end of input 34:9: warning: unused variable 'mymap' [-Wunused-variable] 37:9: warning: unused variable 'loop' [-Wunused-variable] 38:9: warning: unused variable 'loop2' [-Wunused-variable] 100:1: error: expected '}' at end of input 54:5: warning: label 'std' defined but not used [-Wunused-label]
Last edited on
Topic archived. No new replies allowed.