c++ program...... help me.......

Thread Starter

transistor_circuit

Joined Mar 9, 2009
4
how to create a program that save an information into a data base or into the hard drive???


example...


enter a name>>>
then it will save it...

enter an age......
than it will save it...



enter an email...
then it will save...



please reply
 

digitalmind

Joined Mar 7, 2009
30
Do you know the basics of C++ programming? I'm just asking to see if you'd be able to modify and use some example code posted.

Do you need a database, e.g. a C++ programme that works with MySQL for example? Or will a text file be good enough?

Here's something you could go on based on what you've written.

Rich (BB code):
#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main()
{
     string name, age, email;

     cout << "Name >";
     getline( cin, name );

     cout << "Age >";
     getline( cin, age );

     cout << "Email >";
     getline( cin, email );

     ofstream txtfile;
     txtfile.open( "data.csv" );

     txtfile << name << ','
              << age << ','
              << email << endl;

     txtfile.close();
}
C:\> g++/gxx -o simple.exe -O2 -g simple.cc
C:\> simple
...etc.

It omits error checking and things like that as you can see. Is that sort of what you're looking for, a simple programme to write data to a text file which might be looked at or read by another programme at some time?
 

Mark44

Joined Nov 26, 2007
628
Do you know the basics of C++ programming? I'm just asking to see if you'd be able to modify and use some example code posted.

Do you need a database, e.g. a C++ programme that works with MySQL for example? Or will a text file be good enough?

Here's something you could go on based on what you've written.

Rich (BB code):
#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main()
{
     string name, age, email;

     cout << "Name >";
     getline( cin, name );

     cout << "Age >";
     getline( cin, age );

     cout << "Email >";
     getline( cin, email );

     ofstream txtfile;
     txtfile.open( "data.csv" );

     txtfile << name << ','
              << age << ','
              << email << endl;

     txtfile.close();
}
C:\> g++/gxx -o simple.exe -O2 -g simple.cc
C:\> simple
...etc.

It omits error checking and things like that as you can see. Is that sort of what you're looking for, a simple programme to write data to a text file which might be looked at or read by another programme at some time?
It also omits such subtleties as allocating space for strings, so although it will probably compile, it will almost certainly generate errors at run time.
 

digitalmind

Joined Mar 7, 2009
30
It also omits such subtleties as allocating space for strings,
This is C++, and objects are allocated automatically on the stack. The memory handling for the string value is taken care of automatically by the class, and comes from the heap.

Notice I did not declare a pointer to a string.

so although it will probably compile,
It sure does.

it will almost certainly generate errors at run time.
No it does not. It works fine. You might like to read Stroustrup's books on C++.
 
Top