////////////////////////////////////////////////////////////////////////////////////////
// In this little project I am trying to learn to get and manipulate data from
// a file input using fstream strings I also wanted to use the formating available
// with the printf and related string handling methods. I have a question in regards
// to the two usages that I have shown in order to get char * from std::string.
//
// Is there a differance between the two things I have done?
// Is one safer than the other because of allocatin for size?
// Does it matter?
//
// Does anyone have any comments or suggestions regarding this code?
// I have a severe case of the newbies, and this is just getting my toes wet
// a little bit, so bear with me here.
//
// Thank You for Your Kind indulgence.
// 73
// -Grace
// NNNN
// z
////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string STRING;
char * ptrNewBuffer = new char[STRING.size() + 1];
const char* StringBuffer;
int main ()
{
ifstream infile;
ofstream outfile;
outfile.open("MyOuput.txt");
infile.open ("ReadWriteLine.cpp");
while (!infile.eof())
{
// infile is this file since it changes and it's fun
getline(infile, STRING);
// method 1
strcpy(ptrNewBuffer, STRING.c_str());
printf("%s\n", ptrNewBuffer); // output once
// method 2
StringBuffer = STRING.c_str();
printf("%s\n", StringBuffer); // now output twice
//was cout<<STRING<<endl;
// experiment with output file
outfile<<STRING<<endl; //try replace cout eith outfile
}
infile.close();
outfile.close();
system("PAUSE");
return(0);
}
// -eof-