Need guidance on this c++ program. Kind of confused

So I am writing a program. I ahven't programed in a year do to a medical issue but I am back in it. WE have to write a word counter program that reads the words in a file whose name is given through the command line. We then have to output it in alphabetical order and say how many times a word appears. WE have to use STL map and use OO. I have most of it written out but im not understanding it. someone help?
*Confused* :/
How can u have most of it written out but not understand what u wrote ? Know the design before coding it...
Last edited on
Well there a some parts I've written. It's just instantiating my class in main
Show your code(use code tags PLEASE), and comment out the spots you cant understand. We need something to work with.
absolutely.

My Header File:



#ifndef WORDCOUNTER_H
#define WORDCOUNTER_H
#include <map>

#include <string>
using namespace std;

class WordCounter
{

public:

map<string, int>* my_map;
string tempstr;
WordCounter();// constructor set tempstr to ' '
void ReadChar();// use map here to read in words and print

};
#endif

My .cpp file for my header:

#include "lab1.h"
#include <iostream>
#include <map>
#include <string>
#include<stdio.h>
#include<string.h>


using namespace std;

//sets value of value to 0
WordCounter::WordCounter()//DONE
{
my_map = new map<string, int>;
tempstr = "";

}

int WordCounter::ReadChar()
{

//map<string, int> my_map;

string my_word;// This is an input buffer for the word
my_map.insert(pair<string,int>(my_word,1));

pair< map<string,int>::iterator , bool> > my_return;
// May fail
my_return = my_map.insert(pair<string,int>(my_word,1));

// Return failed
if(ret.second == false)
{
// increment the value of the map element
}

map<string, WordCounter,less<string> >::iterator it;

for ( it = counter.begin();it != counter.end(); it++ )
{
cout << it.first() << ' ' << it.second() << endl;
}


}

My Main.cpp:

int main(int argc, char *argv[])
{
WordCounter word_count;

string buffer, my_word;
//ifstream my_ifile;

ifstream my_ifile(argv[1], ios::in);//reads file from input line
my_ifile.open();

if(!my_ifile)
{
return 1;
}
while (my_ifile.getline(buffer) != false)
{
word_count.insert(pair<string,int>(my_word,1))
}

}


Most of this im sure is wrong :/

Show your code(use code tags PLEASE), and comment out the spots you cant understand. We need something to work with.
Hey why not try in scripting, like batch script or shell scripts ? That would be much helpful in it..
Topic archived. No new replies allowed.