HelpCreate multiple files from a variable.

Posts 16–19 of 19 · Page 2 of 2
Quote Originally Posted by Sixx93 View Post
I think that you cannot use the '+' to build a string as in vb.net...

Well, I've always failed trying do that.
You can use '+' to do whatever you want in C++. See overloaded operator.
Quote Originally Posted by Fovea View Post
You can use '+' to do whatever you want in C++. See overloaded operator.
Oh ok, but it works just for the string var from #include <string>.
And still,the code itself,copy pasted (and with added includes cause why not) directly into dev c (changed to int main() ) doesn't work for me as the to_string command is causing issues it seems O.o
And yeah,i've made sure <string> is there /weeeeird
If anyone was still wondering,i managed to do it this way (however it doesn't spam it on the desktop,but on the actual folder)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

ofstream prova;
int main()
{
	string a,b="spam",c=".txt",d;
	char u=48,i=48,o=48,p=48;
	bool stop=false, first=true;
	//48-57
	int x,y=0,z;
	cin>>x;
	while(y<x)
	{
		a=u;
		a+=i;
		a+=o;
		a+=p;
		p++;
		if(p>57)
		{
			p=48;
			o++;
			if(o>57)
			{
				o=48;
				i++;
				if(i>57)
				{
					i=48;
					u++;
					if(u>57)
					{
						if(first==true)
						{
							u=65;
							first=false;
						}
					}
					else if(u>90)
					{
						stop=true;
					}
				}
			}
		}
		if(stop==false)
		{
		d=b+a+c;
		prova.open(d.c_str(),ios::app);
		prova << "lol.\n";
		prova.close();
		cout<<d<<endl;
		y++;
		}
		else
		{
			break;
		}
	}
	system("pause");
}
It outputs file from spam0000 to spam9999,then proceeds from spamA000 to spamZ999.
huehue.
Posts 16–19 of 19 · Page 2 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us