i have a text file "test.txt" with "This is a secret file" in it. I want to read in the whole sentence in with white spaces and manipulate each character. How can i do this? My current method leaves out white spaces.

const int SIZE = 17;
char string2[SIZE];
ifstream fin;

fin.open("test.txt");
for (int n=0; n<SIZE; n++)
{
fin >> string2[n];
}

for (int n=0; n<SIZE; n++) //output is just for testing purposes 
{
cout << string2[n];
}

use getline() instead of >> operator. fin.getline(string2, sizeof(string2)); Or if you use std::string

std::string string2;
getline(fin, string2);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.