My Visual C++ is starting to really um... screw up to put it nicely

This is a discussion on My Visual C++ is starting to really um... screw up to put it nicely within the C++ Programming forums, part of the General Programming Boards category; Looks like header files just don't work anymore. Especially the good old <string.h>. I made a test just to see ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    48

    My Visual C++ is starting to really um... screw up to put it nicely

    Looks like header files just don't work anymore. Especially the good old <string.h>.

    I made a test just to see if something was wrong... and there was.

    Here's the codes that I've tried
    Code:
    #include <iostream>
    #include <string.h>
    
    int main()
    {
    	string str1="Strings don't work with my Visual C++ 6.0";
    	cout<<str1;
    	return 0;
    }
    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
    	string str1="Strings don't work with my Visual C++ 6.0";
    	cout<<str1;
    	return 0;
    }
    Code:
    #include <iostream>
    #include <cstring>
    
    int main()
    {
    	string str1="Strings don't work with my Visual C++ 6.0";
    	cout<<str1;
    	return 0;
    }
    And as luck would have it I always get the same errors:

    Code:
    --------------------Configuration: Testing - Win32 Debug--------------------
    Compiling...
    main.cpp
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(6) : error C2065: 'string' : undeclared identifier
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(6) : error C2146: syntax error : missing ';' before identifier 'str1'
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(6) : error C2065: 'str1' : undeclared identifier
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(6) : error C2440: '=' : cannot convert from 'char [42]' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(7) : error C2065: 'cout' : undeclared identifier
    c:\program files\microsoft visual studio\myprojects\testing\main.cpp(7) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
    Error executing cl.exe.
    
    Testing.exe - 5 error(s), 1 warning(s)
    So what's wrong with my Visual C++ and is there any other way to fix it besides re-installing it? Or am i just stupid? (please don't say that because it won't really help the situation even though it could be true)
    Hey, you gotta start somewhere

  2. #2
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    Try putting the ".h" after iostream on your first code posting, and a statement to hold the screen.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    48
    nope...
    Hey, you gotta start somewhere

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    17
    Well I don't know if this is what you're looking for.. but I got it to work like this...

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
    	string str1="Strings don't work with my Visual C++ 6.0";
    	cout<<str1;
    	return 0;
    }

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    If you're using the current standard for headers, without the .h, you need to add a using statement, e.g.,
    using namespace std;
    Some people consider it wasteful to add the entire std namespace, so they'll add just the individual components they're using:
    using std::cout;
    using std::cin;
    etc.
    If you don't add the using statements, each time you use one of the components from the header libraries you must prefix it with std::
    std::cout << "You must use std::cout in this case";
    This seems tedious to me, but some people do code that way.
    Truth is a malleable commodity - Dick Cheney

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    <string.h> != <string> so #include <string> in all your files.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using classes
    By krazykrisi in forum C++ Programming
    Replies: 9
    Last Post: 11-22-2006, 09:41 AM
  2. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  3. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 03:07 PM
  4. Starting to program games in visual c++
    By Leeman_s in forum Game Programming
    Replies: 14
    Last Post: 11-05-2001, 04:37 PM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21