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. C / C++ / MFC
  4. ofstream problems

ofstream problems

Scheduled Pinned Locked Moved C / C++ / MFC
c++iosgame-devdata-structuresquestion
2 Posts 2 Posters 0 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.
  • C Offline
    C Offline
    CS925
    wrote on last edited by
    #1

    Hi, I am writing a C++ program and am trying to send an array of integers to a text file, however, when I open the text file, it looks like this: ⰸⰶⰰⰹⰲⰰⰰⰰⰰⰰⰰⰲⰴⰶ At an earlier part in the program, I sent an array of integers, but the file came out like I intended it to. I don't know why it doesn't come out correctly for the other piece of code. This is the code that doesn't work correctly: ofstream game(name.c_str()); if(game.is_open()) { for(int i = 0; i < 81; i++) { game << g_ivalues[i] << ","; } game.close(); } Please note that all the variable listed are declared. This piece of code does work correctly for me though: ofstream profiles(name.c_str(), ios::out); if(profiles.is_open()) { for(int i = 0; i < 100; i++) { profiles << g_ipuzplayed[i] << ","; } } profiles.close(); Any thoughts on why they don't work the same? Thanks in advance!

    Chris

    D 1 Reply Last reply
    0
    • C CS925

      Hi, I am writing a C++ program and am trying to send an array of integers to a text file, however, when I open the text file, it looks like this: ⰸⰶⰰⰹⰲⰰⰰⰰⰰⰰⰰⰲⰴⰶ At an earlier part in the program, I sent an array of integers, but the file came out like I intended it to. I don't know why it doesn't come out correctly for the other piece of code. This is the code that doesn't work correctly: ofstream game(name.c_str()); if(game.is_open()) { for(int i = 0; i < 81; i++) { game << g_ivalues[i] << ","; } game.close(); } Please note that all the variable listed are declared. This piece of code does work correctly for me though: ofstream profiles(name.c_str(), ios::out); if(profiles.is_open()) { for(int i = 0; i < 100; i++) { profiles << g_ipuzplayed[i] << ","; } } profiles.close(); Any thoughts on why they don't work the same? Thanks in advance!

      Chris

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      CS925 wrote:

      game << g_ivalues[i] << ",";

      What is g_ivalues? Does the following work?

      for(int i = 0; i < 81; i++)
      {
      cout << g_ivalues[i] << ",";
      }


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      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