Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. How to output STL string into a file

How to output STL string into a file

Scheduled Pinned Locked Moved ATL / WTL / STL
c++businesstutorialquestion
2 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael Liu
    wrote on last edited by
    #1

    How to output string into a file? My part of code is belowLook at the last line, it is not ok.) // Open the file ready write if((pOutputFileStream = fopen(csFilePath, "w")) != NULL) bStatus = TRUE; // Otherwise output message to the console window. else { printf("The output %s file is not available!", csFilePath); bStatus = FALSE; } if (bStatus) { // STL string. string str = vNode.back (); cout << str << endl; // // this line is not ok. // fprintf(pOutputFileStream, "%s", str.substr); } Thanks. mIchAel Liu __________________________________________________________ The secret of business is to know something that nobody else knows. ;)

    C 1 Reply Last reply
    0
    • M Michael Liu

      How to output string into a file? My part of code is belowLook at the last line, it is not ok.) // Open the file ready write if((pOutputFileStream = fopen(csFilePath, "w")) != NULL) bStatus = TRUE; // Otherwise output message to the console window. else { printf("The output %s file is not available!", csFilePath); bStatus = FALSE; } if (bStatus) { // STL string. string str = vNode.back (); cout << str << endl; // // this line is not ok. // fprintf(pOutputFileStream, "%s", str.substr); } Thanks. mIchAel Liu __________________________________________________________ The secret of business is to know something that nobody else knows. ;)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You're using C++ to output to the console, and C to output to the file. Use iostreams instead. #include <iostream> #include <fstream> #include <string> using std::string; using std::ofstream; ... string s("This is a test of the veracity of my system"); ofstream op("c:\\test.txt"); op << s; // can call op.close(), but the destructor does it anyhow. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups