Why cant it get to work?

Basically I have a text file.
And I have four long strings, with spaces between them.
What I am trying to do is to get those lines and putting them in the array called 'apple'

Here is the code

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
 #include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
int main()
{

	ifstream inputFile;
	int const Array_Size = 4; 
	char Apple[Array_Size];
	int count = 0;
	inputFile.open("VirusPatterns.txt");
	cout << "Reading the virus signature. \n";

	for(; count < Array_Size; count++)
	{
		inputFile >> Apple[count];
	}

	inputFile.close();

	for (int index = 0; index <= count; index++)
		cout << Virus[index] << endl; 

	return 0;
}


The issue is, that I am getting only the first letters of the line, I want to get the whole line in that array, even though they have spaces between them.

The question is how?

anyone kind enough to tell?
Yalai ya heee hee anyone?
@stuckinthehouse

You've declared the Apple array to be a char, which is one character. Try changing it to a string, instead of char.

Then, to read the entire line as one input, use getline( inputFile, Apple[count] );
Last edited on
@Whitenite1

I did try it, the problem is that it does not copies the text after the spaces, for example

asdfghi jklmnb

I want to take this whole line from txt file.

If I use string I will get only this part :

'asdfghi' and it will ignore 'jklmnb'

and if I use char I will only get 'a' because it is the first letter =/

anyone?
read it into a std::string first.

although, have you done what whitenite said and use getline()?
YESHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!!!!!

Finally man!

Thanks whitenite!
Topic archived. No new replies allowed.