wildworld_ammsa Posted August 27, 2004 Share Posted August 27, 2004 (edited) hello every1 i want to write a program that automatically makes files like 1.txt,2.txt,3.txt,... Can any1 help me please? :wacko: Edited August 27, 2004 by wildworld_ammsa Link to comment Share on other sites More sharing options...
0 bwx Posted August 28, 2004 Share Posted August 28, 2004 hello every1i want to write a program that automatically makes files like 1.txt,2.txt,3.txt,... Can any1 help me please? :wacko: If you just want to make the files, this code will do: #include <string> #include <fstream> #include <sstream> std::string numToStr (int n) { std::stringstream ss; std::string ret; ss << n; ss >> ret; return ret; } int main (int argc, char **argv) { const int startFrom = 0; // the number to start from when creating files const int maxFiles = 100; // the last number for ( int i = startFrom; i <= maxFiles; ++i ) { std::string tmpFile = numToStr(i) + ".txt"; std::fstream fStream; fStream.open( tmpFile.c_str(), std::ios::out | std::ios::trunc ); if (fStream.is_open()) fStream.close(); fStream.clear(); } return 0; } Hope that helps. Link to comment Share on other sites More sharing options...
0 wildworld_ammsa Posted August 28, 2004 Author Share Posted August 28, 2004 thanx BWx but i get the following error: error C2653: 'std' : is not a class or namespace name Link to comment Share on other sites More sharing options...
0 John Veteran Posted August 28, 2004 Veteran Share Posted August 28, 2004 thanx BWx but i get the following error: error C2653: 'std' : is not a class or namespace name :s Umm, what compiler are you using? Link to comment Share on other sites More sharing options...
0 wildworld_ammsa Posted August 28, 2004 Author Share Posted August 28, 2004 It works now i needed VS.NET to compile it thanx. Link to comment Share on other sites More sharing options...
0 bithub Posted August 28, 2004 Share Posted August 28, 2004 Just in case you want to see the C way... FILE *f; char szFile[64]; for(int i = 1; i < 5; i++) { sprintf(szFile,"%d.txt",i); f = fopen(szFile,"r"); fclose(f); } Link to comment Share on other sites More sharing options...
0 wildworld_ammsa Posted August 28, 2004 Author Share Posted August 28, 2004 This actually what i wanted but now i'm using the other one thanx you bithub. Link to comment Share on other sites More sharing options...
Question
wildworld_ammsa
hello every1
i want to write a program that automatically makes files like 1.txt,2.txt,3.txt,... Can any1 help me please? :wacko:
Edited by wildworld_ammsaLink to comment
Share on other sites
6 answers to this question
Recommended Posts