0

Ok, here's my code:

string connect;
	
	cout<<"enter node, then linked nodes";
	cin>>node;
	while(node != 0)
	{
                 cin.get( connect );
                 adjList.insert(make_pair(node,connect));   
                 cin>>node;
             }

The problem at hand is that the compiler (Dev C++) keeps telling me :
21 no matching function for call to `std::basic_istream<char, std::char_traits<char> >::get(std::string&, char)'

referring to cin.get( connect );

Can anyone point out what the heck I'm missing right now??? :mad:

If you need more code let me know.

2
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by Narue
0

istream::get doesn't have an overload for std::string. You're probably thinking of getline:

getline ( cin, connect );
0

Thanks a bunch Narue. Now kinda a side question - is there any way (built in functions) of parsing integers from a string? Like in Java there is the parseInt function. Does c++ have anything remotely close to this?

Thanks again,
Nate

0

>Like in Java there is the parseInt function.
C++ has a more flexible method using stringstreams. Alternatively, you could use sscanf:

#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>

int main()
{
  std::string num = "10";
  std::stringstream ss ( num );
  int i, j;

  // Using stringstream
  ss>> i;
  std::cout<< i * 2 <<'\n';

  // Using sscanf
  std::sscanf ( num.c_str(), "%d", &j );
  std::cout<< j * 2 <<'\n';
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.