LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   readArgFromFile’ was not declared in this scope (https://www.linuxquestions.org/questions/programming-9/readargfromfile%92-was-not-declared-in-this-scope-4175496730/)

Aska123 03-02-2014 08:07 AM

readArgFromFile’ was not declared in this scope
 
Hello friends

I tried following example to calculate different delay between nodes

first I created a file named config.txt which has values

Code:

//config.txt
 Number of node = 11
 Link delay = 1 2 3 4 5 6 7 8 9 10

next a cc program to calculated link delay

Code:

//sim.cc
#include<stdlib.h>
#include <iostream>
#include <fstream>
#include <math.h>
#include <cstdio>

 int main(int argc, char* argv[]) {
 float delay = 0, d[10];
 FILE* fp = fopen(argv[1],"w");
 int i, num_nodes = readArgFromFile(fp,d);
 for(i = 1; i < num_nodes; i++)
 delay += d[i-1];
 printf("Overall Packet Delay is %2.1f seconds\n",
delay);
 fclose(fp);
 }

when I try to compile the program s follows
[code]
g++ -o sim sim.cc
i got error
Code:

In function ‘int main(int, char**)’:
sim.cc:10: error: ‘readArgFromFile’ was not declared in this scope


millgates 03-02-2014 08:28 AM

What's readArgFromFile? Where is it defined?

Aska123 03-02-2014 09:01 AM

Thanks for reply

I have taken this example from book Introduction to NS-2
Teerwat_Issariyakul

I do not know how to read arguments from text file. and how to use them in c++
I have to read number of nodes from txt file and also link delay between them

millgates 03-02-2014 09:37 AM

As far as I know, there is no such function in any of the standard C++ libraries. Either the book you are reading provides its definition, or you'll have to implement it yourself. For reading from files, you'll need either methods from fstream (alternatively, you may use the old style plain C cstdio).

If you're unsure about how to do this, I strongly recommend that you familiarise yourself with the basics of C++ (the sticky thread here in the programming section has a lot of resources for learning C/C++) before continuing with your book.

Aska123 03-02-2014 11:12 PM

Ok millgates


All times are GMT -5. The time now is 10:17 AM.