This has been bothering me for a while and c++ is not my strongest language so I'm hoping someone can help me out with this.
What I need to do is open a text file, perform some modifications (change all lines that contain only a single period to a single period followed by a space), then save the file with changes.
If there is a better way to make the changes to the text file, I am all for it. This is what I found and I was able to get it to work if I set the temporary file to something fixed, say "temp.txt", however I need this name to be unique, and theEnv->fPath will always give me a unique file name.
The error I get is: cannot convert from 'const char*' to 'char '
If I use the commented line instead, I get a similar error converting from std::string to char
Again my c++ is pretty weak, any help would be greatly appreciated.
//theEnv->fPath provides the path to the file I need to modify
outfile = theEnv->fPath;
outfile = outfile + ".txt";
char outfilename = outfile;
//char outfilename = outfile.c_str();
if (inbuf.length() ==1)
if (inbuf == '.') inbuf = ". ";
outstream << inbuf << endl;
result = remove(theEnv->fPath);
if (result == 0) printf("Delete ok.");
else printf("Delete error.");
result = rename(outfilename, theEnv-fPath);
if (result==0) printf("Rename ok.");
else perror("Rename error.");