Weird, won't let me declare....

This is a discussion on Weird, won't let me declare.... within the C++ Programming forums, part of the General Programming Boards category; OK, I included these files: Code: #include <windows.h> #include <vector> #include <cstring> #include <fstream> I'm using Dev-C++, and I tried ...

  1. #1
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532

    Weird, won't let me declare....

    OK, I included these files:
    Code:
    #include <windows.h>
    #include <vector>
    #include <cstring>
    #include <fstream>
    I'm using Dev-C++, and I tried to declare a vector, an iterator for the vector, and a string like this:
    Code:
    vector<string> messages;
    vector<string>::iterator forward;
    string vtext;
    Now, for some reason, I get these stupid errors:
    Code:
    9 C:\TS.cpp `string' does not name a type 
    10 C:\TS.cpp `vector' undeclared (first use this function)
    Then more errors saying that messages, forward, and vtext are not declared. Why would it do this?? I have used vectors before and used strings many many times. This is ridiculous, it will probably turn out to be something stupid. Well, thanks for any help.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    For string types, you need to include <string>. <cstring> contains functions for null terminated character arrays, i.e cstyle strings.

    You also need some kind of using declaration for the std namespace, e.g.

    using namespace std;

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    By the way, did you know a string is an STL container?
    Code:
    #include<iostream>
    #include<string>
    #include<algorithm> //reverse()
    
    using namespace std;
    
    int main()
    {
    
    	string str = "hello world";
    	
    	reverse(str.begin(), str.end());
    	
    	cout<<str<<endl;
    	
    	return 0;
    }
    Last edited by 7stud; 11-24-2005 at 06:19 AM.

  4. #4
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Yes, I knew that type string was in the std namespace. I found the problem, it was something else that affected it. Thanks.
    Last edited by jmd15; 11-24-2005 at 07:34 AM.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird things with my linked list of queue
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 10:23 PM
  2. Programmatically declare vectors
    By franse in forum C++ Programming
    Replies: 15
    Last Post: 11-10-2008, 02:17 PM
  3. How to declare a list in another list???
    By zaracattle in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2006, 08:24 AM
  4. Declare a template class as a friend?
    By AH_Tze in forum C++ Programming
    Replies: 11
    Last Post: 05-19-2004, 09:24 PM
  5. Getting weird characters in Strings
    By steve8820 in forum C Programming
    Replies: 3
    Last Post: 09-18-2001, 02:49 AM

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