c++ saving to a text file using vs2003

am trying to do a simple save to a text file, even created a file incase this is what i needed, but still will not run any iedeas would be helpful
thanks in advance

// test save 2.cpp : main project file.

#include "stdafx.h"
 #include <iostream>
   #include <fstream>
   #include <string>
   using namespace std;

using namespace System;

int main(array<System::String ^> ^args)
{
    char str[10];

  //Creates an instance of ofstream, and opens example.txt
  ofstream a_file ( "C:\log\example.txt" );
  // Outputs to example.txt through a_file
  a_file<<"This text will now be inside of example.txt";
  // Close the file stream explicitly
  a_file.close();
  //Opens for reading the file
  ifstream b_file ( "C:\log\example.txt" );
  //Reads one string from the file
  b_file>> str;
  //Should output 'this'
  cout<< str <<"\n";
  cin.get();    // wait for a keypress
  // b_file is closed implicitly here
      
      Console::WriteLine(L"Hello World");
    return 0;
}
sydneyguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
A single backslash means the next character is an escape character in a string.
 
ofstream a_file ( "C:\log\example.txt" );
should be
 ofstream a_file ( "C:\\log\\example.txt" );

and
 ifstream b_file ( "C:\log\example.txt" );
should be
 ifstream b_file ( "C:\\log\\example.txt" );

Does it now work as you expect?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sydneyguyAuthor Commented:
thanks for that works like a dream
thnks for tor the help
0
AndyAinscowFreelance programmer / ConsultantCommented:
Your welcome, don't forget the blackslash effect applies to any string, not just file names.  (Just one usually notices something wrong in file names when running the app).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.