cout<<"\n\n Please Input The Drive Letter Of Your Input Device \n";
    cin>>DRL;
    string str(DRL);
    string str2(":");
    string src;
    string hi;
    src=str.find_last_of(DRL);
    cout<<src;
    if(src!=str2)

    {
        hi=string(DRL)+string(str2);
        cout<<hi;
        }


else*/
cout<<hi;

[What am i dong wrong.i am trying to enure a colon input in the drive letter regardless of user input.well it does work if i don't input a semicolon,but if i do it adds a semicolon regardless.What's wrong

Recommended Answers

All 8 Replies

The find_last_of function takes more than one parameter. You're trying to feed it just one parameter.

Here are the find_last_of functions. Pick one.
http://www.cplusplus.com/reference/string/string/find_last_of/

I'm a newbie and that link doesn't bode well with me.would you be kind enough to provide me with a relevant example in my case

That page gives the four variations of the function that you can use. Note that in three of them, there is a default value provided for pos so you can feed it just one parameter if you need you, and accept the default value for the unspecified parameter.

All four of them return an object of type size_t. Generally, this is a number.

When you try to do this:

src=str.find_last_of(DRL);

where src is a string, you're telling the compiler that you want to use the find_last_of function that returns a string. There is no such function. Try

int position;
position=str.find_last_of(DRL);

That page gives the four variations of the function that you can use. Note that in three of them, there is a default value provided for pos so you can feed it just one parameter if you need you, and accept the default value for the unspecified parameter.

All four of them return an object of type size_t. Generally, this is a number.

When you try to do this:

src=str.find_last_of(DRL);

where src is a string, you're telling the compiler that you want to use the find_last_of function that returns a string. There is no such function. Try

int position;
position=str.find_last_of(DRL);

That you for solving that bit
However it opened up a new one
in

if(src==str2)

i get
error: no match for 'operator==' in 'src == str2'

What frustrates me even more is that This is a program i wrote in c, tried and tested,but have been assigned to rewrite in c++.I am thankful for your help though.
not this colon checker bit though

error: no match for 'operator==' in 'src == str2'

Whatever types src and str2 are, the compiler does not know how to carry out the operator == on them. What types are they?

error: no match for 'operator==' in 'src == str2'

Whatever types src and str2 are, the compiler does not know how to carry out the operator == on them. What types are they?

What i'm trying to do is check if DVL has a colon.I not then add a colon.If my way is not the right way ,please enlighten me on a more sensible and/or feasible way.

DVL is a char[2]
src is an int
str2 is a sring

it is rightfully not sensible to compare an int and a string to see if they're identical.

If you want to check if the string DVL contains a colon, try this:

#include<iostream>
#include<string>


int main()
{

  std::string DVL("something with:in the middle");

  if (-1 != DVL.find(':'))
  {
    std::cout << "Found a colon";
  }
  else
  {
    std::cout << "Did not find" << std::endl;
  }

 return 0;
}

it is rightfully not sensible to compare an int and a string to see if they're identical.

If you want to check if the string DVL contains a colon, try this:

#include<iostream>
#include<string>


int main()
{

  std::string DVL("something with:in the middle");

  if (-1 != DVL.find(':'))
  {

Thanks Man you are 
    std::cout << "Found a colon";
  }
  else
  {
    std::cout << "Did not find" << std::endl;
  }

 return 0;
}

Thank you very much
That worked and solved my problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.