Hiya!
I've been getting some different errors
I get a
1."warning C4603: 'read_words': macro is not defined or definition is different after precompiled header is use"
and a
2."error C1020:unexpected #endif"
For the first error I am not sure what I am supposed to see in order to fix it and for the second error I am confused why its unexpected.
--------------------------------------------------------
Also, when I define the function readwords() in another item, these problems are fixed, but I get 3 errors: "LNK2005'...'","LNK2005:_main already defined in project 3.obj", and"LNK1169:one or more multiply defined symbols found. proect 3.exe".
I don't see the point of putting read_words in a separate file. Why not just declare/define it in the main file? Also while including .cpp files isn't disallowed it is not good practice. Can cause linker and symbol issues like the ones you are experiencing.
I'll need readwords function in a different file (practicing headers).
I get the same errors when I transfer read_words.cpp contents to read_words.h and change the #include "read_words.cpp" to #include "read_words.h" in project 3.cpp.
#pragma once
#ifndef READ_WORDS_H
#define READ_WORDS_H
#include <iostream>
#include <vector>
#include <string>
void readwords(std::vector<std::string> &words) // pass in reference to vector
{
std::string x;
words.clear();
std::cout << "Input words -> ";
try
{
while (std::cin >> x) // had to hit Ctrl-Z to end input loop
{
words.push_back(x);
}
} catch (std::exception e) // catches possible exception but you don't bother displaying it
{
std::cout << "There was an error, dawg.\n";
}
}
#endif
project 3.cpp
1 2 3 4 5 6 7 8 9 10
#include "read_words.h"
int main()
{
std::vector<std::string> words;
readwords(words); // will pass in words to function for population because readwords takes reference
std::cout << words.at(0);
return 0;
}
Thank you Texan40,
That cleared 3 of the 5 errors that came up from my Visual Studio Express.
The two that are displaying now are
"error LNK2005: _main already defined in project 3.obj" in source.obj
and
" error LNK1169: one or more multiply defined symbols found" in project.exe
These seem to be an issue with the compiler itself. Not really sure how to approach it other than opening a new project and moving contents over.