Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hello all, i just recently got started programming in C++ using tutorials on the web and i'm learning how to read and wright to text files however i am stuck. i want my program to simply output the # 1-100 to a text file which is created, however i can't figure out exactly how to do this, the code i have so far is
[code]
#include <cstdlib>
#include <iostream>
#include <conio.h> // for getch()
#include <fstream> // for ofstream
using namespace std;int main()
{
ofstream a_file( "numbers.txt" );
int x;
cout<<"this program will make a txt file called numbers and output 0 - 100 in it";
for ( int x = 0; x < 100; x++); // make x inrement up to 100a_file << x; // only prints the actual x not the variable??
a_file.close(); // closes file
getch(); // wait for keypress
};[/code]
hopefully someone can help me with this problem, as i said before i'm really new to this language so i might of made some other mistakes as well...thanks in advance,
also i am using Dev c++ latest version

#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#include <fstream.h>int main()
{
ofstream a_file( "numbers.txt" );
int x;
for ( x = 0; x <= 100; x++) a_file << x << '\n';
a_file.close();
}
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |