How to read and display strings in C ? - TechRepublic
Question
September 29, 2010 at 10:07 AM
fafdsfs

How to read and display strings in C ?

by fafdsfs . Updated 15 years, 9 months ago

so i have a txt file and the first line is “Rain Fall Average”

what code can i use to read the first line and then display it on the console window.

this is what i have so far.

#include
#include
using namespace std;
int main()
{

ifstream inputFile;
char study_name[71]; //NOTE – study name must contain up to 70 character//

inputFile.open(“c:\\rainfall.txt”);
cout << "Reading data from file" << endl; inputFile >> study_name; //Problem here – It only displays “Rain”//
cout << study_name << endl; inputFile.close(); //is it possible displaying the title with a char variable or must i use a string //

This discussion is locked

All Comments