Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8509477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:26:42+00:00 2026-06-11T03:26:42+00:00

I’m a bit confused with all the namespaces for vector and how to properly

  • 0

I’m a bit confused with all the namespaces for vector and how to properly return a vector of strings in my class. Here is the code:

main.cpp

#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include "lab1.h"

using namespace std;
readwords wordsinfile;
words wordslist;

int main ( int argc, char *argv[] )
{
    if ( argc != 2 ) {
            // Looks like we have no arguments and need do something about it
            // Lets tell the user
            cout << "Usage: " << argv[0] <<" <filename>\n";
            exit(1);
    } else {
            // Yeah we have arguements so lets make sure the file exists and it is readable
            ifstream ourfile(argv[1]);
            if (!ourfile.is_open()) {
                    // Then we have a problem opening the file
                    // Lets tell the user and exit
                    cout << "Error: " << argv[0] << " could not open the file. Exiting\n";
                    exit (1);
            }

            // Do we have a ASCII file?
            if (isasciifile(ourfile)) {
                    cout << "Error: " << argv[0] << " only can handle ASCII or non empty files. Exiting\n";
                    exit(1);
            }

            // Let ensure we are at the start of the file
            ourfile.seekg (0, ios::beg);
            // Now lets close it up
            ourfile.close();
    }

    // Ok looks like we have past our tests
    // Time to go to work on the file
    ifstream ourfile2(argv[1]);
    wordsinfile.getwords(ourfile2);

lab1.h

#ifndef LAB1_H
#define LAB1_H

bool isasciifile(std::istream& file);

class readwords {
    public:
             int countwords(std::istream& file);
             std::vector<std::string> getwords(std::istream& file);
};

class words {
    public:
            void countall( void );
            void print( void );
};

#endif

lab1.cpp

#include <fstream>
#include <iostream>
#include <map>
#include "lab1.h"
#include <vector>
using std::vector;
#include <string>

using namespace std;

vector<string> readwords::getwords(std::istream& file) {
    char c;
    string aword;
    vector<string> sv;
    int i = 0;

                    while(file.good()) {
                            c = file.get();
                            if (isalnum(c)) {
                                    if(isupper(c)) {
                                            c = (tolower(c));
                                    }
                                    if(isspace(c)) { continue; }
                                    aword.insert(aword.end(),c);
                            } else {
                                    if (aword != "") {sv.push_back(aword);}
                                    aword = "";
                                    i++;
                                    continue;
                            }
                    }
    return sv;
}

Here is the error from compiling.

g++ -g -o lab1 -Wall -pedantic main.cpp lab1.cpp
In file included from lab1.cpp:4:0:
lab1.h:9:4: error: ‘vector’ in namespace ‘std’ does not name a type
lab1.cpp:48:54: error: no ‘std::vector<std::basic_string<char> > readwords::getwords(std::istream&)’ member function declared in class ‘readwords’
make: *** [lab1] Error 1

Why do I get this error and how do I fix it. Thank you for any help you can provide.

Ryan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:26:44+00:00Added an answer on June 11, 2026 at 3:26 am

    You have to #include <vector> in the header file as well. Actually, including it in the header is enough, as all files including that header will implicitly also include <vector>.

    The thing is your include order is:

    #include "lab1.h"
    #include <vector>
    

    and since you use std::vector in the header (before including it) you get the error. Reversing the include order would fix the compilation error, but doesn’t solve the underlying error – that lab1 uses symbols that weren’t defined yet. The proper fix is to include <vector>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.