• 15
• 15
• 11
• 9
• 10

# whats wrong with this code?

This topic is 4032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

string::size_type laengde(const vector<string>& v)
{
string::size_type maxlen = 0;
for(vector<string>::size_type i = 0; i != v.size; ++i)
maxlen = max(maxlen, v.size());

return maxlen;
}

vector<string> frame(const vector<string>& v)
{
vector<string> ret;
string::size_type maxlen = laengde(v);
string border(maxlen + 4, '*');

ret.push_back(border);

for (vector<string::size_type i = 0; i != v.size(); ++i)
{
ret.push_back("* " + v + string(maxlen - v.size(), ' ') + " *");
}

ret.push_back(border);
return ret;
}

int main()
{
string v;

cout << "fortael mig lidt om dig selv: ";
string >> v;

cout << endl << frame(v) << endl;
return 0;
}


these is my errors:
Quote:
 Error 1 error C3867: 'std::vector<_Ty>::size': function call missing argument list; use '&std::vector<_Ty>::size' to create a pointer to member c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 11 Error 2 error C2446: '!=' : no conversion from 'unsigned int (__thiscall std::vector<_Ty>::* )(void) const' to 'unsigned int' c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 11 Error 3 error C2040: '!=' : 'unsigned int' differs in levels of indirection from 'unsigned int (__thiscall std::vector<_Ty>::* )(void) const' c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 11

##### Share on other sites
Add parentheses to the call to size in the condition of the for loop.

##### Share on other sites
Quote:
 Error 1 error C3867: 'std::vector<_Ty>::size': function call missing argument list; use '&std::vector<_Ty>::size' to create a pointer to member c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 11

Quote:
 'std::vector<_Ty>::size': function call missing argument list; use '&std::vector<_Ty>::size' to create a pointer to member

Then, find about what he's talking about: it mentions the "size" member function of a vector. You have one in "v.size". It also says that the argument list is missing.

The solution is simple: add the ().

##### Share on other sites
thanks! i must had overlooked it.. :(

it now tells me that i have a problem in the for loop in this function:

vector<string> frame(const vector<string>& v){ vector<string> ret; string::size_type maxlen = laengde(v); string border(maxlen + 4, '*');  ret.push_back(border);  for (vector<string::size_type i = 0; i != v.size(); ++i)  {    ret.push_back("* " + v + string(maxlen - v.size(), ' ') + " *");  }    ret.push_back(border);  return ret;}

errors:
Quote:
 Error 1 error C2146: syntax error : missing ',' before identifier 'i' c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 24Error 2 error C2065: 'i' : undeclared identifier c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 24Error 3 error C2143: syntax error : missing ',' before ';' c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 24

sorry for me seeming helpless, but ive been trying to figure this out all day :(

##### Share on other sites
for (vector<string::size_type i = 0; i != v.size(); ++i)

You are missing a closing '>' after 'string', unless that is a forum typo.

for (vector<string>::size_type i = 0; i != v.size(); ++i)

##### Share on other sites
Quote:
 Error 1 error C2146: syntax error : missing ',' before identifier 'i' c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 24

Clean up the error:

Quote:
 missing ',' before identifier 'i'

So, find the identifier i on line 24:

for (vector<string::size_type i = 0; i != v.size(); ++i)

If necessary, split it into multiple lines (one i per line). However, it isn't necessary here, as an identifier can always be safely preceded by ; or ; ++. So, the problem is with:

vector<string::size_type i

Which only takes a few seconds to notice that the closing > of the vector template is missing.

##### Share on other sites
i cant help making pathetic laughter at myself >_<x100

alright. I strike back with a (hopefully) not as dum question as previus.

how do i 'convert' a string into a vector?

#include <iostream>#include <vector>#include <string>#include <cctype>using namespace std;string::size_type laengde(const vector<string>& s){ string::size_type maxlen = 0; for(vector<string>::size_type i = 0; i != s.size(); ++i) 	maxlen = max(maxlen, s.size());    return maxlen;}vector<string> frame(const vector<string>& s){ vector<string> ret; string::size_type maxlen = laengde(s); string border(maxlen + 4, '*');  ret.push_back(border);  for (vector<string>::size_type i = 0; i != s.size(); ++i)  {    ret.push_back("* " + s + string(maxlen - s.size(), ' ') + " *");  }    ret.push_back(border);  return ret;}  int main(){  cout << "fortael mig lidt om dig selv: ";string s;while (getline (cin, s)){ vector<string> v = frame(s); for (vector<string>::size_type i = 0; i != v.size(); ++i)  cout << endl << frame(s) << endl; }return 0;}

errors: (pointing to the main(), in the 'vector<string> v = frame(s);' line
Quote:
 Error 1 error C2664: 'frame' : cannot convert parameter 1 from 'std::string' to 'const std::vector<_Ty> &' c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 42Error 2 error C2664: 'frame' : cannot convert parameter 1 from 'std::string' to 'const std::vector<_Ty> &' c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 44

##### Share on other sites
Sorry, it's still just as dumb. The compiler error literally explains to you what the problem is. It's not like you encountered some unfathomable template trickery that's gone horribly wrong.

Quote:
 Error 1 error C2664: 'frame' : cannot convert parameter 1 from 'std::string' to 'const std::vector<_Ty> &' c:\Documents and Settings\mads\Dokumenter\Visual Studio 2005\Projects\dasdfg\dasdfg\da.cpp 42

Cleaned up:

Quote:
 'frame' : cannot convert parameter 1 from 'std::string' to 'const std::vector<_Ty> &'

It says that the argument 1 of function frame in your code is of type std::string, but function frame expects an argument of type vector, and it could not convert from one to another. In short, you've provided an incorrect type of argument.

##### Share on other sites
i know that, im sorry for not explaining probaly, but i dont know how to 'convert' it. i mean.. they are both vector<string>..

no matter what changes i make in the argument/returntype and so on it gives me a million new errors. im freaking out! i ask you, please show me what im doing wrong.

##### Share on other sites
Quote:
 Original post by MadsGustafi know that, im sorry for not explaining probaly, but i dont know how to 'convert' it.

This isn't really a relevant question here. This particular error is not a minor compiler nitpick (such as a missing '>', an unclosed comment, or some other stupid error), it's telling you that you said one thing when declaring frame, and you're now saying another thing when using frame. You're being inconsistent with yourself, which is a clear sign that you are confused about your own code (which is a dangerous thing). So, the question to be asked here is not about the conversion, but about why you're being inconsistent in the first places. Two simple questions, in fact:

Question 1: why does frame take a vector of strings as argument? You chose to wrote it that way, so why?

Question 2: why are you trying to call frame on a line that was just read from standard input?

Asking these questions should reveal that you either incorrectly designed frame (so it should take a string as argument, instead of a vector of strings), or that you are incorrectly using it, and you should be calling another function, or passing another argument.