Ok, here is a program....im getting an error, "est.cpp(1) : fatal error C1083: Cannot open include file: 'stream.h': No such file or directory
Error executing cl.exe."

I know something is wrong with the header...and i think it cannot read the cout (in bold). Im trying to run this in (Microsoft) Visual C++. Does it make a difference?? Can someone see where im making my mistake? Thank you again.

#include <sstream.h>
#include <string.h>  

using namespace std;

bool StringToInt(const string &s, int &i);

int main(void)
{
  string s1 = "12";
  string s2 = "ZZZ";
  int result;
  
  if (StringToInt(s1, result))
  {
    [B]cout[/B] << "The string value is " << s1
         << " and the int value is " << result << endl;
  }
  else
  {
    cout << "Number conversion failed" <<endl;
  }
  if (StringToInt(s2, result))
  {
    cout << "The string value is " << s2
         << " and the int value is " << result << endl;
  }
  else
  {
    cout << "Number conversion failed on " <<s2 <<endl;
  }    
  return(0);
}

bool StringToInt(const string &s, int &i)
{
  istringstream myStream(s);
  
  if (myStream>>i)
    return true;
  else
    return false;
}

Thanks in advance.

Replace your headers with these

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

Amazing! Thank you once again. I may need your help later on sunnypalsingh with doing a string search and returning all the numbers in a set, (say 48098, 50933, 3129, 5) as integers. But now that i know how to find one, i think i can just implement the code for finding the others as well. I will post another thread in due time. Thanks!

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.