Displaying a set of data

I don't want a whole program written for me, I just need some tips or what type of loops I should use, or if I should even use any loops at all. Thanks!

So I am trying to create a program that will display different sets of data. I will be getting the sets of data by importing the file by using linux redirection. The issue I am having is how to go about displaying the sets of data and how to get the data from the file.

I can't think of a way to do it. I understand a loop will have to be used however I don't know much about loops to understand how to display different sets of data for each loop and how I can collect them.

I will receive, at the beginning of the file how many sets of data I will have to display and each set of data will be different from the last, so how would I go about doing this without writing five hundred different statments to display random sets of data and 500 cin statements to collect the actual sets of data.

I hope I was clear if I wasn't please ask for me to be more clear because I truly do need help.
Last edited on
redirection is done via command line, take the following code:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>

int main(void)
{
    std::string word;
	std::cin >> word;
	std::cout << word << std::endl;
	return 0;
}


Compiled as "wordcopy", redirect via command line:
1
2
3
4
$ wordcopy // cin and cout are from/to console
$ wordcopy >output.txt // cin is from console, cout is to "output.txt"
$ wordcopy <input.txt // cin is from "input.txt", cout is to console
$ wordcopy <input.txt >output.txt // cin and cout are from/to files 


enhancing the program to use a set of data printed/read to/from file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>

class Data
{
private:

	std::string word;
	int number;

public:
	Data(void)
		:word(""), number(0)
	{}
	Data(std::string word, int num)
		:word(word), number(num)
	{}
	~Data(void)
	{}
	
	void read(void)
	{
		std::cin >> word >> number;
	}
	
	void print(void)
	{
		std::cout << word << " " << number << std::endl;
	}
};


int main(void)
{
	Data myData("Hello", 25);
	myData.print();
	myData.read();
	myData.print();
	
	return 0;
}

Last edited on
Can you please explain that more in depth for me please? I want to understand what I am writing. The string word; at the top what is that for? I am using numbers also, it is one line of data however their are multiple parts that need to be used I have to separate out the data myself. Would the code that you used above help do that???
Last edited on
Topic archived. No new replies allowed.