Hi ! I am using C++ to create a new .inf file but problem I am facing that I am not able to enter the 2nd line in new line. code is : Code: #include<iostream.h> #include<fstream.h> void main() { ofstream newfile; newfile.open("c:\example.inf") newfile<<"First Line \n"; newfile<<"Second Line \n"; newfile.close() } output in file is: First LineSecond Line Kindly rectify me here
Sir ! I tried this code. but It removes the First character of First Line. Source is: Code: #include<iostream.h> #include<conio.h> #include<process.h> #include<fstream.h> void main() { char sample[1000]; ofstream myfile; myfile.open("c:/example.txt"); myfile<<"Writing in the file."; myfile<<"\r \n Next line"; cout<<"Done"; } Output in file is : Code: riting in the file. Next Line But I don't understand how did it happen? Like if I tell what i understands from this code. I take example of notepad here. Like I opened a text file in notepad. I typed "Writing in the file" then I press HOME key on key board which is I think equivalent to \r(Carriage Return). Then I type Next Line. Now the Output would be here as follows : Code: Next LineWriting in the file. Kindly make me understand.
Thank you Shabbir. It worked.I found my error. Actually i was giving a space between /r and /n which was replacing first character. Thanks Once again.