8 Replies - 348 Views - Last Post: 19 November 2012 - 03:02 PM Rate Topic: -----

#1 4N63L-Z3R0  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 94
  • Joined: 19-October 12

Insert File into program?

Posted 18 November 2012 - 04:22 PM

The program I have posted below is still in progress. I believe I understand how to do the calculations needed, but what is stopping me is I am not sure how to get the program to actually extract the separate file & use the information in it.

// Rain_or_Shine_N.cpp : Defines the entry point for the console application.

// This program belongs to Nichole Moore.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
	const int ROW = 3; // Months.
	const int COLS = 30; // Day of month.
	int weather[ROW][COLS]; // 3 x 30 array.
	string monthNames[ROW] = {"June", "July", "August"};
	int r, c;
	ifstream datafile;
	int rain = 0, cloud = 0, sun = 0, month = 0, day = 0, x;
	char rainy = 'R';
	char cloudy = 'C';
	char sunny = 'S';
		
	cout << "Rain or shine\n";
	cout << "________________________\n";

	// Open file.
	datafile.open("RainOrShine.dat");
	
	// Read data.
	cout << "Weather Report\n\n";
	for (r = 0; r = ROW; r++)
	{
		for (c = 0; (r = COLS); c++)
		{
			cout << datafile;
		}
	}

	return 0;
}


Any help or explanation is very much appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: Insert File into program?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5439
  • View blog
  • Posts: 11,669
  • Joined: 02-June 10

Re: Insert File into program?

Posted 18 November 2012 - 04:31 PM

You do know that both July and August have 31 days, right? So your array isn't large enough.
Was This Post Helpful? 1
  • +
  • -

#3 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Insert File into program?

Posted 18 November 2012 - 05:09 PM

Exactly how to get the data into weather[][], depends on their format, in the data file.

Show a few columns of a few rows of the data file, and what you've tried to read it in.
Was This Post Helpful? 0
  • +
  • -

#4 4N63L-Z3R0  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 94
  • Joined: 19-October 12

Re: Insert File into program?

Posted 18 November 2012 - 06:54 PM

tlhIn`toq, thank you very much for the heads up!



View PostAdak, on 18 November 2012 - 05:09 PM, said:

Exactly how to get the data into weather[][], depends on their format, in the data file.

Show a few columns of a few rows of the data file, and what you've tried to read it in.


Adak, I am not sure what you mean?
Was This Post Helpful? 0
  • +
  • -

#5 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: Insert File into program?

Posted 18 November 2012 - 06:57 PM

How is the information stored in the file, binary or text?
Was This Post Helpful? 0
  • +
  • -

#6 4N63L-Z3R0  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 94
  • Joined: 19-October 12

Re: Insert File into program?

Posted 18 November 2012 - 07:15 PM

Oh! Well the textbook is saying to use a .dat file. But I wasn't sure how to use that, so I made a text file with the same info in it.

So long story short, a text file.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5439
  • View blog
  • Posts: 11,669
  • Joined: 02-June 10

Re: Insert File into program?

Posted 19 November 2012 - 09:09 AM

I think your terminology is confusing people.
Are you trying to actual insert a file into a program for distribution so it includes the file?

Or are you just trying to read/write a text file?
Was This Post Helpful? 0
  • +
  • -

#8 4N63L-Z3R0  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 94
  • Joined: 19-October 12

Re: Insert File into program?

Posted 19 November 2012 - 02:46 PM

I am actually trying to open the file with the program so the information in the file is able to be used in order to make calculations based on the info provided within the file.
Was This Post Helpful? 0
  • +
  • -

#9 TheChessDevil  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 19-November 12

Re: Insert File into program?

Posted 19 November 2012 - 03:02 PM

try this:


#include <fstream>
#include <vector>

int main(){

ifstream data("datafile.txt");
int num;
vector <string> vecData;

//put the things in the data file into the vector
while(data>>num){
  vecData.pus_back(num);

}



Was This Post Helpful? 1
  • +
  • -

Page 1 of 1