Login Page - Create Account

Support Board


Date/Time: Mon, 20 May 2024 17:23:21 +0000



[Programming Help] - problem : I do not know how do you retrieve the line in a text file.

View Count: 1490

[2016-06-15 10:18:23]
User210074 - Posts: 63
I do not know how do you retrieve the line in a text file.
I want to recover 1 in this txt file.


#include <iostream>
#include <string>
#include <fstream>
#include "sierrachart.h"
#include <stdio.h>
#include <time.h>
using namespace std;
SCDLLName("Test");
SCSFExport scsf_DTNS(SCStudyGraphRef sc) {
if(sc.SetDefaults){
sc.GraphName="Test";
sc.StudyDescription="Test";
sc.FreeDLL = 1;
   sc.GraphRegion = 0;
}//Fin de la fonction Defaut//
   ifstream Files("Z:\\Sierra_Chart\\Data\\Val.txt", ios::in);//Z:\\SC_Graphique_rithmic\\Data\\Val.txt"
   if(Files){
       //sc.AddMessageToLog("File Open.", 1);
     string Lines;
       while ( getline(Files, Lines) ) {
// .....
       }
Files.close();
       return;
   }//Right
   else{
sc.AddMessageToLog("File Not Open.", 1);
     return;
   }//Wrong
}//Fin de fonction//

In Val.txt

1 // Line 1

How can i retrieved the line in the WHILE ?
I don't Know !
[2016-06-17 14:27:46]
User210074 - Posts: 63
I test that

But it doesn't work


#include <iostream>
#include <string>
#include <fstream>
#include "sierrachart.h"
#include <stdio.h>
#include <time.h>

using namespace std;
SCDLLName("Test");
SCSFExport scsf_DTNS(SCStudyGraphRef sc) {

if(sc.SetDefaults){
sc.GraphName="Test";
sc.StudyDescription="Test";
sc.FreeDLL = 1;
sc.GraphRegion = 0;
}
ifstream Files("Z:\\SC_Graphique_rithmic\\Data\\Val.txt", ios::in);
if(Files){
//sc.AddMessageToLog("File Open.", 1);
string Lines;
while ( getline(Files, Lines) ) {
              std::stringstream Val(Lines);
              int Data, Value;
              std::string Data;
       if ( std::getline(Val, Data, ',') ) { Value = Data; }
       else { Value = ""; }
}
Files.close();
return;
}//Right
else{
sc.AddMessageToLog("File Not Open.", 1);
return;
}//Wrong

}


Error

-- Starting build of Custom Studies Source files: DTS.cpp. -- 16:18:58

"Z:\SierraChart\CPPCompiler\bin\g++.exe" "Z:\SC_Graphique_rithmic\ACS_Source\DTS.cpp" -march=i686 -mtune=i686 -O2 -shared -static -static-libgcc -static-libstdc++ -s -fno-rtti -fno-exceptions -std=gnu++11 -o "Z:\SC_Graphique_rithmic\Data\DTS.dll"

Z:\SC_Graphique_rithmic\ACS_Source\DTS.cpp: In function 'void scsf_DTNS(SCStudyInterfaceRef)':
Z:\SC_Graphique_rithmic\ACS_Source\DTS.cpp:23:34: error: variable 'std::stringstream ss' has initializer but incomplete type
std::stringstream ss(Lines);
^
Z:\SC_Graphique_rithmic\ACS_Source\DTS.cpp:25:20: error: conflicting declaration 'std::string Data'
std::string Data;
^
Z:\SC_Graphique_rithmic\ACS_Source\DTS.cpp:24:12: note: previous declaration as 'int Data'
int Data, Valeur;
^
Z:\SC_Graphique_rithmic\ACS_Source\DTS.cpp:27:34: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
else { Valeur = ""; }
^
-- End of Build -- 16:19:00


[2016-06-17 16:20:07]
Sierra Chart Engineering - Posts: 104368
We do not provide programming help.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account