View Full Version: source code maker

C++ Learning Community > C++ Works in Progress > source code maker


Title: source code maker
Description: not quite working yet


tiptep - December 9, 2005 12:40 AM (GMT)
I just got this exe to run :rolleyes: , but, as you may have predicted, it's still not quite working :( .
CODE
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
ofstream source("source.cpp", ios::app);
string StrSource="#include <iostream>\nusing namespace std;\nint main()\n{\n";
int conout();
int alldone();
int main()
{

int choice;
cout << "What do you want to do?\n";
cout << "\t1.Send text to the screen\n";
cout << "\t2.Save and finish\n";
cin >> choice;
switch (choice)
{
      case 1:
           system("cls");
           return conout();
           break;
      case 2:
           system("cls");
           return alldone();
           break;
      default:
              cout << "eh, that's not a choice\n";
              system("pause");
              system("cls");
              return main();
              break;
}
return 0;
}
int conout()
{
   string message;
   cout << "What text should be sent to the screen(when you're done, press tab then enter)?\n";
   getline(cin, message,'\t');
   StrSource.append ("cout << \"");
   StrSource.append (message);
   StrSource.append ("\" << endl;\n");
   StrSource.erase (63,1);
   cout << "message saved\n";
   cout << StrSource;
   system("pause");
   system("cls");
   return main();
}
int alldone()
{
   cout << "Saving your new source code to source.cpp...\n";
   StrSource.append ("system(\"pause\");\nreturn 0;\n}");
   source << StrSource;
   cout << "Your new source code has been saved, have fun with it ^ _^\n";
   system("pause");
   return 0;
}

When I try to add text, it asks what should be sent to the screen, but doesn't let me input the text, and just skips to the 'message saved'.

I was hoping that atleat my include, namespace, and main would makeit okay, but upon reading the source code generated, it just says 0x43807c. 0x means hex right?

With my luck, it's probably either something simple, or something way over my head.

EDIT:
Okay, I'm so painfully close to getting it to work, how do I get it to finish taking input for the text to the screen, just when the user presses enter, instead of tab enter. It runs, it's just that...

until that's figured out, I'm gonna get started on the rest of the features I wanna add eventually:
  • Name your source what ever you want
  • Save your source where ever you want
  • Manual code edit
  • Compile it if the user doesn't have a compiler (a BIG maybe)
  • The option for cin, variables, random numbers, multiple functions, and whatever else I can think of
  • Instead of a funtion for adding cout, a function for adding cin, a funtion for adding random numbers, etc, just one function for adding anything, that gets the information to add that from an external file. Will make it easier to update

Thanks for any help.

Rmstn1580 - December 9, 2005 02:25 AM (GMT)
You have a smiley in your code... Why still using system("PAUSE"); use cin.get(); it looks a lot better

tiptep - December 9, 2005 02:38 AM (GMT)
QUOTE (Rmstn1580 @ Dec 9 2005, 02:25 AM)
You have a smiley in your code... Why still using system("PAUSE"); use cin.get(); it looks a lot better

oh, lol, thanks for pointing out the smilie, the code actualy said ^ _^ (only without theat first space, I guess you can put smilies in code on the boards too :huh: .

As for system("pause");, that's just how I was first taught, from the first tutorial I read (wish I could remember where) my program flashed and disappeared, after posing on the forums there, someone suggested system("pause"), and I've been using it for development ever since, I suck at breaking habits. But when I do make something that I find worthy to be distributed, I take out system("pause");



Anybody think they could help me?




Hosted for free by InvisionFree