| | |
C++ Input File reading help!!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 1
Reputation:
Solved Threads: 0
Hello guys,
I am new in this forum and i hope im gonna get some fast help.
I have this problem where i should input numbers from a .doc file, and the program should output how many times the number of occurences of each number.
ie: the numbers in the .doc file are 2,3,6,8,9,2,1,1,3,1.
The program should read the numbers from the file and outputs the following:
Number 1 = 3
Number 2 = 1 ... and so on.
I started with the following but im getting stuck.
Any help please??
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{
int array[10000];
ifstream numbers( "numbers.doc", ios::in);
if(!numbers)
{
cerr << endl << "File could not be opened" << endl;
system("pause");
exit(1);
}
for (i=0, i<10000, i++)
array[i] = 0; //initializes array
for (i=0, i<50, i++)
{
if (i=1)
array[n] += array[i];
cout << array[i];
}
{
if (i=2)
array[n] += array[i];
cout << array[i];
}
///and so on.
I appreciate any suggestions and assistance,
Thank u
I am new in this forum and i hope im gonna get some fast help.
I have this problem where i should input numbers from a .doc file, and the program should output how many times the number of occurences of each number.
ie: the numbers in the .doc file are 2,3,6,8,9,2,1,1,3,1.
The program should read the numbers from the file and outputs the following:
Number 1 = 3
Number 2 = 1 ... and so on.
I started with the following but im getting stuck.
Any help please??
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{
int array[10000];
ifstream numbers( "numbers.doc", ios::in);
if(!numbers)
{
cerr << endl << "File could not be opened" << endl;
system("pause");
exit(1);
}
for (i=0, i<10000, i++)
array[i] = 0; //initializes array
for (i=0, i<50, i++)
{
if (i=1)
array[n] += array[i];
cout << array[i];
}
{
if (i=2)
array[n] += array[i];
cout << array[i];
}
///and so on.
I appreciate any suggestions and assistance,
Thank u
Last edited by beast0000; Dec 31st, 2008 at 1:48 pm.
Site rules, "CODE TAGS!"
The usual structure I suggest often, to avoid the whole emergency bail out thing.
You probably should place those loops in a function too.
Where is
You need to format it and place it in code tags, I got lost, and was sure I saw something funky with the brackets after the second for loop.
The usual structure I suggest often, to avoid the whole emergency bail out thing.
C++ Syntax (Toggle Plain Text)
file open if(file.is_open()) { do stuff here; file.close(); } else { cout << "Error!"; }
Where is
i declared?You need to format it and place it in code tags, I got lost, and was sure I saw something funky with the brackets after the second for loop.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
![]() |
Similar Threads
- Reading a input file (C)
- Error with taking input from a file (C++)
- input from file into class (C++)
- Reading an input file as a class memeber function (C++)
- I need help on STRUCTURES and on input file (C)
- How to Read an input file (C++)
Other Threads in the C++ Forum
- Previous Thread: program wont pause
- Next Thread: Win version for atomic.h
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





