Jan 9, 2015 at 3:50pm UTC
No file is created during runtime even when path is specified?//solved. New error on post 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
system("cls" );
char pathin[500];
cout << "Enter path : " ;
cin.getline(pathin,'\n' );
char *path = new char [strlen(pathin)+1];
int i;
for (i = 0; i <= (signed )strlen(pathin); i++)
{
path[i] = pathin[i];
}
path[i] = '\0' ;
ofstream fout(path,ios::_Noreplace);
fout << path;
fout.close();
system("pause" );
return 0;
}
Edit: see post 5
Last edited on Jan 9, 2015 at 7:20pm UTC
Jan 9, 2015 at 5:05pm UTC
Oh, thanks for pointing it out. Actually I copied the string for just adding a '\0' in the end. :p
Jan 9, 2015 at 5:06pm UTC
Strange this does not sorts out the problem.
Jan 9, 2015 at 7:14pm UTC
Ok, seems that creating a file at C:\ is prohibited but there is some problem with string input too. Its not reading more than 9 characters.
Jan 9, 2015 at 7:21pm UTC
What are you entering?
Last edited on Jan 9, 2015 at 7:22pm UTC
Jan 9, 2015 at 8:00pm UTC
If I enter suppose "E:\Newfile.txt"
then only "E:\Newfil" is taken as input. No idea why. Neither I have idea about hot to mess with permissions within the code.
Jan 9, 2015 at 8:07pm UTC
Second argument of std::istream::getline is target buffer size (maximum line size + terminating 0). '\n'
has character value of 10.
Last edited on Jan 9, 2015 at 8:07pm UTC