Repost anyway -- one misplaced semicolon will cause big problems.
Hi the code is below please have a look. it saves the file with user specified name but doesnt include the variable values of a b and c as file name. Someone told me that the compiler is old so let me know if thats the case and sugesst some good and easy to use ones. I am using Borland 3.1.
//using namespace std;
char FirstName, LastName;
cout << "\nEnter the name of the file you want to create: ";
cin >> FileName;
sprintf(filename, "%s,%i.,%i.,%i.txt", FileName, a,b,c);
cout << "Enter First Name: ";
cin >> FirstName;
cout << "Enter Last Name: ";
cin >> LastName;
cout << "Enter Age: ";
cin >> Age;
ofstream Students(FileName, ios::out);
Students << FirstName << "\n" << LastName << "\n" << Age;
cout << "\n\n";
It has nothing to do with the age of your compiler. Line 28 is wrong, you are using the wrong variable as the first parameter. That is one good reason to avoid using two variables with the same name except for capitalization.
Look at line 28. Don't you see the difference between the variable name on line 28 and the variable name on line 18 ????:icon_eek: Variable names are case sensitive, meaning filename is not the same as FileName
I am using windows vista, and you are write about the commas and dots. But i can save the file manually with dots and commas as part of the filename and also when i removed the commas and dots from the program it created a file but not all 3 variable values were printed as filename.
I am also using Vista. Check the directory in which your program is running and I'll bet my boots that the file is there. If you remove all the commas and dots you will get this filename "testing101213txt"
hey thanks for your help, can you give me some ideas about how do i go in generating a number of files say 3 with the same name but the values of a,b and c been incremented by 1 e.g. test11.12.13 etc etc. Can you give me some ideas places.
Right I got that but there is a slight issue with incrementing a fraction number e.g. .01 now what I am trying to achieve is to incerement this .01 by .01 for a number of times and generate output files with the incremented number. For example a=.01 now when the loop runs for once it generates a file say called abc.01.txt next time i increments the value of a by .01 (i.e. now a=.02) and generate another file with name abc.02.txt and so on.
Please explain as i am struggling to achieve this.
How do i go in writing the same file in visual c++ 2005. there are certain commands that dont work with VS C++. Can you please advise. The reason I am doing so because I had no success in printing all the variable values as part of the file name using Borland compiler.
you can use the same methods as above you just need to use the right include files and settings. first make a new win 32 console application and check the box for an empty project. add a new cpp file and include stdio.h like #include <stdio.h> . this will let you use the sprintf function.
Thank you very much for your reply and help. I've solved that problem. Can you guide me in the right direction for below please:
I want to create output files such that one of the three variables value is incremented at a time and that value is stored into the file. For example say i've the following
a=10, b=12,c=14 now wot i want to to acheive is to increment the value of a say by .1 and keep b and c the same for a number of times say 4. and next phase a and c are kept same but b and incremented by .1 and then save into the file and same for c. One way that I can think of doing this is by using loops and typing the same statements again and again which will make the code too lengthy.