cin problems(think)

(using windows xp):program doesn't seem to want to execute cin(im using cin here so window doesn't just close) code is


[code]
[#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <windows.h>
using namespace std;
int count(string c,char a);
int size(string a);
int main()
{
WIN32_FIND_DATA fileinfo;
char *dir,*filename,*data,*tmp;
string s;
int i,*c,u;
dir=new char[MAX_PATH];
filename=new char[MAX_PATH];
cout << "input directory" << endl;
cin >> dir;
/*cin.ignore();*/
strcpy(filename,dir);
strncat(dir,"/textfile.rtf",13);
fstream filefile(dir,ios::in);
if(filefile.is_open())
{
filefile >> filename;
while(!filefile.eof())
{
fstream reader(filename,ios::in);
if(reader.is_open())
{
getline(reader,s,'\0');

i=(count(s,'\t')+count(s,'\n'));
data=new char[size(s)];
tmp=new char[size(s)];
c=new int[i];
i=0;
while(s[i]!='\0')
{
data[i]=s[i];
i=i+1;
}
strcpy(tmp,data);
i=0;
while(tmp[0]!='\0')
{
tmp=strtok(data,"\t\n");
c[i]=atoi(filename);
i=i+1;
}
cout << s << endl << endl;
cout << c << endl;
reader.close();
}
else cout << "unable to open\t" << filename << endl;
filefile >> filename;

}
}
else cout << "unable to open directory file" << endl;
filefile.close();
/*cin.clear();*/
cin >> u;
return 0;
}
int count(string c,char a)
{
int k,q;
k=0;
q=0;
while (k<=size(c))
{
q=q+(c[k]==a);
k=k+1;
}

return q;
}
int size(string a)
{
int n=0;
while(a[n]!='\0')
{
n=n+1;
}
return n-1;
}
]


thought it might be associated with memory management issues?
so tried ignore and clear unsuccessfully
any ideas?
I believe it is because in the beginning, you are using cin to get a character, but cin still has the \n inside of it, so when you get the cin>>u; line, it already has a \n in the buffer and just exits immediately.

For the record, code tags go like this:

[code]
your code
[/code]
thanks firedraco, im kinda new to it all i guess
It's all good :)
Topic archived. No new replies allowed.