error LNK2019 unresolved external symbol

I'm trying to write code to read and display 10 integer values from a text file.

When I try to compile my code, I get an error that says "LNK2019 unresolved external symbol". I can't figure out what's wrong with how I'm declaring my functions.

My code is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "lab7.h"
#include <fstream>
#include <iostream>
#include <string>

using std::ifstream;
using std::ofstream;
using std::string;
using std::cout;
using std::endl;

const int NUMBER_OF_INTS = 10;

void readInts( string file, string myInts[] );
void showMeMyInts( const string myInts[], int count );

void readInts( string file, string myInts[] )
{
	ifstream in(file);
	int intCount = 0;
	in.ignore( 500, '\n' );
	
	string ints;
	
	in >> ints;
	while( !in.fail() )
	{
		if ( intCount < NUMBER_OF_INTS )
		{
			myInts[intCount]=ints;
			intCount++;
		}
		in >> ints;
	}
}

void showMeMyInts( const string myInts[], int count )
{
	for ( int i=0; i<count; i++ )
	{
		cout << myInts[i] << endl;
	}

}



My main is:

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include "lab7.h"
using std::cout;
using std::cin;
using std::endl;

int main()
{
    readInts( "inputLab7.txt", "outputLab7.txt");
}



Thanks.
Last edited on
Function declaration:

1
2
void readInts( string file, string myInts[] ) //array of string
{


Function call:
readInts( "inputLab7.txt", "outputLab7.txt");

Please use code tags in future. http://www.cplusplus.com/articles/z13hAqkS/
Look at your declaration for readInts() and how you're calling it:

Declaration:
 
void readInts (string file, string myInts[] );


How you're calling it:
 
  readInts ("inputLab7.txt", "outputLab7.txt");

Do you see the problem? The declaration is expecting an array of std::strings. You're passing a const char * which gets promoted to a single std::string.

This should not even have compiled.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Last edited on
Topic archived. No new replies allowed.