String trouble. I suspect my compiler.

I'm running visual c++ 6.0 enterprise. The following won't compile, even though I copied it directly from the source reference on this website. I added the ".h" on all my includes, etc. It keeps telling me std isn't a valid namespace, and I tried every "workaround" i could think of.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream.h>
#include <string.h>

using namespace std;
using std::string;

int main ()
{
	std::string s0 ("Initial string");

  // constructors
	std::string s1;
  std::string s2 (s0);
  std::string s3 (s0, 8, 3);
  std::string s4 ("A character sequence", 6);
  std::string s5 ("Another character sequence");
  std::string s6 (10, 'x');
  std::string s7a (10, 42);
  std::string s7b (s0.begin(), s0.begin()+7);

  cout << "s1: " << s1 << "\ns2: " << s2 << "\ns3: " << s3;
  cout << "\ns4: " << s4 << "\ns5: " << s5 << "\ns6: " << s6;
  cout << "\ns7a: " << s7a << "\ns7b: " << s7b << endl;
  return 0;
}
line 1 and 2 shoule be
1
2
#include <iostream>
#include <string> 


That's the way it should be but I'm not sure if your compiler accepts it. I have heard a lot of bad things about visual c++ 6.
Last edited on
:\program files\microsoft visual studio\vc98\include\ostream(9) : fatal error C1083: Cannot open include file: 'ios': No such file or directory

That's what it says when I remove the ".h"
My suggestion is not to use vc++ 6.0 for the modern standard libraries. CString of Mfc is what I would use for vc++ 6.0. I would go to a different compiler that understands the modern standards of C++. VC++ 6.0 was before the 98 standard was finalized, I believe. I do know there is a version of the STL that can compiler on it but I don't know what of the 98 standard it might expect to get to it.

Under vc++ 6.0 it might not have <string> library, which is part of the 98 STL standard. The Using command may not be part of it as well. Name spaces weren't required on that compiler.
Azagaros, I'm assuming vc++ 2012 express would work with the 98 standard?
Topic archived. No new replies allowed.