Need help with Visual Studio C++

hnaderi

Junior Member
Jun 1, 2005
2
0
0
Hey, i hope someone out here can help me out. I've recently switched to visual studio pro 6.0 to finsih up this school project, but i can't seem to run a simple program on it at all! I get errors when i even try to output to the console or when i include standard libraries (string, ifstream). For instance, here is an error code for the following line of code:

string word = "testword";

error C2065: 'string' : undeclared identifier


I did put in the include statement:
#include <string>
also tried
#include <string.h>

isn't string part of the standard library of C++? Why is visual c++ giving me so many problems? did i not set up the project correctly? Please hep!!
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
I don't think string.h actually gives you a string datatype. I usually use it to have access to string related functions like memcpy and strcpy which take arrays of chars or char pointers.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
VS6 is very, very old and it's known to have gaping holes in it's C++ standards support, but I don't think strings is one of those since it's a pretty basic datatype. Did you even try looking in the MSDN docs that came with it?
 

Spydermag68

Platinum Member
Apr 5, 2002
2,616
99
91
Looked up <string> in VS.NET

// basic_string_ctor.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

void main( )
{
using namespace std;

// The first member function initializing with a C-string
const char *cstr1a = "Hello Out There.";
basic_string <char> str1a ( cstr1a , 5);
cout << "The string initialized by C-string cstr1a is: "
<< str1a << "." << endl;

// The second member function initializing with a string
string str2a ( "How Do You Do?" );
basic_string <char> str2b ( str2a , 7 , 7 );
cout << "The string initialized by part of the string cstr2a is: "
<< str2b << "." << endl;

// The third member function initializing a string
// with a number of characters of a specific value
basic_string <char> str3a ( 5, '9' );
cout << "The string initialized by five number 9s is: "
<< str3a << endl;

// The fourth member function creates an empty string
// and string with a specified allocator
basic_string <char> str4a;
string str4b;
basic_string <char> str4c ( str4b.get_allocator( ) );
if (str4c.empty ( ) )
cout << "The string str4c is empty." << endl;
else
cout << "The string str4c is not empty." << endl;

// The fifth member function initializes a string from
// another range of characters
string str5a ( "Hello World" );
basic_string <char> str5b ( str5a.begin ( ) + 5 , str5a.end ( ) );
cout << "The string initialized by another range is: "
<< str5b << "." << endl;
}
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
#include <string>

but also put a using namespace std; statement after the includes, because string should be part of the namespace std <-- i don't remember if VC6 observes this rule but it's worth a try

you can also access string like this: std::string blah = "dafd"; without the using statement (note the std:: )
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
Originally posted by: dighn
#include <string>

but also put a using namespace std; statement after the includes, because string should be part of the namespace std <-- i don't remember if VC6 observes this rule but it's worth a try

you can also access string like this: std::string blah = "dafd"; without the using statement (note the std:: )

vc6 does have the string (and other STL classes) in the "std" namespace.
 

hnaderi

Junior Member
Jun 1, 2005
2
0
0
great, thanks for all the help guys, the problem was i didn't include :

using namespace std;

I had actually put that line before all my #include's, which ended up in a compiler error and so had then commented it out, after putting it after everything is as sweet and dandy like sour candy (as ned flanders would say it)