By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

How can I use file path to be output in a txt file

P: 14
Hello,

Can anybody give me hint in how I to copy a file path and then output the same file path on a different *.txt file?

This is the code I have:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.  
  9.  
  10.  
  11.  
  12.  
  13.     // external variables
  14.     ifstream in;
  15.     ofstream outData;
  16.     const string PATH = "C:\Program Files\Internet Explorer\IEXPLORE.EXE" ";
  17.  
  18.  
  19.     PATH.substr(0, 46);
  20.  
  21.     outData.open("destination.txt");
  22.     outData << PATH ;
  23.  
  24.     outData.close();
  25.  
  26.     return 0;
  27.  
  28. }
  29.  
However, when I compile I get this error:

program.cpp
program.cpp(17) : warning C4129: 'P' : unrecognized character escape sequence
program.cpp(17) : warning C4129: 'I' : unrecognized character escape sequence
program.cpp(17) : warning C4129: 'I' : unrecognized character escape sequence
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

/out:program.exe
program.obj

Thank you for any help or feed back.
Mar 22 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 1,510
the \ character is used as an escape character in C/C++, e.g. \n is newline, \t is tab, etc. so when you use it in a string you have to use \\, e.g.
Expand|Select|Wrap|Line Numbers
  1. const string PATH = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE" ";
  2.  
Mar 22 '07 #2

P: 14
Hello Horace,

Your suggestiperfectly worked!!! This is great!

Do you know of any particular table on which I could refer to when using these type of characters?

Such as:

~1, @, so on so forth...

I thank you kindly!
Mar 23 '07 #3

Roonie
P: 99
http://www.developerz.com/cplusplus_escapesequences.htm

search for "c++ escape characters"
Mar 23 '07 #4

P: 14
Thank you Roonie!
Mar 23 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.