The visual studio c++ program compiles and build without errors. When i try to run it from the black screen, it says: Prgram.exe has encountered a problem and needs to close. We are sorry for the inconvenience. I believe I wrote this code before and it worked without problems. I don't understand why it will not work now. I could be wrong, it's been awhile. PLEASE KINDLY HELP?
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
string fileName,line;
ifstream infile;
cout<<"Enter the file name and complete path: ";
cin>>fileName;
int count=0;
string *A;
infile.open(fileName.c_str());
while(!infile.eof())
{
getline(infile,line);
if(line[count]=='A'||line[count]=='a')
{
A=new string[count];
A[count]=strlen(line.c_str());//THIS LINE IS CAUSING AN ERROR
cout<<A[count]<<endl;
count++;
}
}
return 0;
}
I did make a mistake. It's been a long time since I programmed. I am trying pass a string such as a name into A[]. Maybe I used the wrong syntax. I copied it from an old program I wrote. Can you please clarify how to pass the input string to string array instead of: A[count]=strlen(line.c_str())