get() put() read and write functions from online source

I am stumped. MAJORLY. Here is the assignment for this particular function, I have already finished 9 other functions(one with help from here :D), but this one is hard haha.


Using the get() and put() iostream functions, read in a .txt version of Pride and
Prejudice from http://www.gutenberg.org, apply the count word function to see how many words are in the fina, apply your sum ascii function, apply your single spaces, and write out the new string to a new file.


Word count and sum ascii functions are working properly, but they require a STRING, not a file. So this is the <b>unworking</b> function I have. I just want to know if I'm on the right track, or if I should take a completely different route(and what the other route is, if I do need a different one). Should I be using ios::binary to handle this large of a 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
int writePrideandPredjudice()
{
	fstream streamObject;
	ifstream localFile;
  
	int count = 0;
	
	
	streamObject.open("http://www.gutenberg.org/cache/epub/1342/pg1342.txt", ios::out);
	localFile.open("prideandprejudice_file.txt", ios::in);
	streamObject << localFile.rdbuf();

	
	string stringOfText[localFile.length()];

	for(int i = 0, i < localFile.length(); i++)
	{
		stringOfText[i] = localFile.get(i);
		count++;
	}

	string spongebob(stringOfText[count]);//(don't ask... couldn't think of any more names haha)
	countWords(spongebob);
	sumAscii(spongebob);
	doubleToSingleSpace(spongebob);

	return 0;

}


I need to write the doubleToSingleSpace to a new .txt(or the existing one), but I don't know how... The rest of my function, well if you know more than me at C++, you can see it's all garbage. I really don't understand this well... and I've done quite a bit of reading on it. Any help is greatly appreciated.
Last edited on
bump... I also haven't used the get or put functions... and wouldn't even know how to(even though I've read up on them.... this file is really big. do I get the internet source and put into the text file?... grrr that just sounds stupid haha) I really need help on this and haven't found anything similar from an internet source to a txt file...
Last edited on
bump
So, this would work, but it wont open either the internet source, nor the .txt file ( I even tried to do an absolute file name)... kind of lost here... I have no idea how to get the internet or the .txt file to actually open(It just keeps saying they failed to load)

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
42
43
44
45
46
47
48
int writePrideandPredjudice()
{
	string enormous;
	fstream streamObject("http://www.gutenberg.org/cache/epub/1342/pg1342.txt");
	fstream localFile("pap.txt");
	fstream newFile("new.txt");
	
	

	if(streamObject.fail())
		cout << "file failed to load." << endl;
	else
		cout << "file load was successful." << endl;
	
	if(localFile.fail())
		cout << "file2 failed to load." << endl;
	else
		cout << "file load was successful." << endl;
	
	while(!streamObject.eof())
	{
		streamObject.put(localFile.get());
	}

	streamObject.close();

	char single = localFile.get();
	while(!localFile.eof())
	{
		enormous += single;
		single = localFile.get();
		
	}
	localFile << newFile;

	localFile.close();

	countWords(enormous);
	doubleToSingleSpace(enormous);
	sumAscii(enormous);





	return 0;

}
ok so the

1
2
3
countWords(enormous);
doubleToSingleSpace(enormous);
sumAscii(enormous);


are your other functions in your 10 functions you are righting for this that you need to apply to the text right?

string enormous; ?? what is the code this refers too elswhere in your project?
Topic archived. No new replies allowed.