File I/O

Hello, I need some help with my program. I'm trying to get the contents of one file to another file but right now, it only prints the last word from the original to the copy file.
I know I need to do something with the while loop, like have a nested for loop that prints the words to the other file then increments down the list of words.
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
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>

std::string next;


int main( int argc, char** argv) {

	std::ifstream inStream;
	inStream.open("words.txt");
	if ( inStream.fail()) {
		std::cout << "Input file opening failed.\n";
		exit(1);
	}

	while(inStream >> next) {
		//inStream.push_back(next);
		}
			inStream.close();

	std::ofstream outStream("triangle.txt", std::ios::app);
		outStream << next << std::endl;
	outStream.close();
	return 0;

}

Just copying a file is a one-liner.

What kind of transformation are you trying to do? Reducing whitespace to minimum?
This code is part of a much bigger one.
I have a list of words that are in the words.txt file and I have to use tn = 1/2 n (n+1) (triangle numbers) to turn each letter of each word into a number and add those "letters" together and copy the "Triangle" words into the other file.
I was trying to get the copying of everything done first before I tackle the harder part of that.


That's still not very clear.

How does a letter turn into a number?

Once you add the letter values of a word together, you get a number. Is that number supposed to be a triangle number in order to OK copying the word to the output file?
Topic archived. No new replies allowed.