2 Replies - 391 Views - Last Post: 13 October 2012 - 05:41 AM Rate Topic: -----

#1 zazk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 13-October 12

Can't cout a vector<string>

Posted 13 October 2012 - 05:08 AM

The book I'm reading didn't make it very clear to me how to use vector<string>.There was an example of using it in class and then I tried to use it in my own program but then I got the Error:no argument matches these operands
on the "<<" before the values[i].It only allows me to print a single character if I add a second [] but I want the whole string.Where am I wrong?
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	vector<string> values;
	values.push_back("Menu");
	values.push_back("Option");
	for (int i = 0; i < values.size(); i++)
	{
		cout << i + 1 << ") " [b]<<[/b] values[i] << endl; 
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Can't cout a vector<string>

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4025
  • View blog
  • Posts: 12,432
  • Joined: 25-December 09

Re: Can't cout a vector<string>

Posted 13 October 2012 - 05:35 AM

You probably need to include the <string> header to properly use the string class.

Jim
Was This Post Helpful? 1
  • +
  • -

#3 zazk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 13-October 12

Re: Can't cout a vector<string>

Posted 13 October 2012 - 05:41 AM

Shame on me for missing it.Thank you for the help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1