Help with small vector.h class

D

Dark Knight

Hello,

I am working on a program to get use to the vector.h Templete class.

Program:

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int main()
{
vector<string> v;
ifstream in("FillVector3.cpp");
string line;
while(getline(in, line))
v.push_back(line);
for(int i=0;i<v.size();i++)
cout<<i<" : "<<v<<endl;
return 0;
}

It gives me 9 errors:

8 error c2784 "'declaration' : could not deduce template argument for 'type'
from 'type'"
1 error c2677 "binary 'operator' : no global operator defined which takes
type 'type' (or there is no acceptable conversion)"
 
A

Attila Feher

Dark said:
Hello,

I am working on a program to get use to the vector.h Templete
class.

Template class? And please: no .h said:
cout<<i<" : "<<v<<endl;


Look at those < signs closely. Shouldn't you have two of them everywhere?

This what I can see from the code. Since you did not share with us the line
numbers where the errors are and the concrete error messages this is the
best I can do for you now.
 
M

Mike Wahler

Dark Knight said:
Hello,

I am working on a program to get use to the vector.h Templete class.

Program:

#include <string>
#include <iostream>
#include <fstream>
#include <vector>

#include said:
using namespace std;

int main()
{
vector<string> v;
ifstream in("FillVector3.cpp");

if(!in)
{
cerr << "Cannot open input\n";
return EXIT_FAILURE;
}
string line;
while(getline(in, line))
v.push_back(line);
for(int i=0;i<v.size();i++)

Not the problem, but should be:

for(vector said:
cout<<i<" : "<<v<<endl;


cout << i << " : " << v << endl;
return 0;
}

Note that use of whitespace as in my correction
makes these errors easier to spot, and imo
makes the code generally easier to read.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top