Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,857 questions

51,778 answers

573 users

How to read words from text file into array in C++

1 Answer

0 votes
#include <iostream>
#include <array>
#include <string>
#include <fstream>

using std::cout;
using std::endl;
using std::array;
using std::string;

int main()
{
	array<string, 10> arr;
	
	std::ifstream in("d:\\data.txt");

	string word;
	int i = 0;
	while (in >> word)
		arr[i++] = word;

	in.close();
	
	for (string val : arr)
		cout << val << endl;

	return 0;
}

/*
run:

python
java
c#
php
c++

*/

 



answered May 7, 2018 by avibootz

Related questions

1 answer 151 views
1 answer 134 views
1 answer 304 views
1 answer 225 views
1 answer 151 views
1 answer 237 views
1 answer 231 views
...