Login Page - Create Account

Support Board


Date/Time: Thu, 18 Apr 2024 13:04:46 +0000



[Programming Help] - C++ std::string to SCString

View Count: 1476

[2020-08-26 11:25:44]
User253985 - Posts: 21
How do i get characters from a std::string into a SCString.

example

const char* SheetCollectionName = "TesterWesterSpreadsheet";
  const char* SheetName = "Sheet1";
  void* SheetHandle = sc.GetSpreadsheetSheetHandleByName(SheetCollectionName, SheetName, false);

  std::ifstream longs (testerwester.csv");
  SCString messagee = "File Open Error";
  if(!longs.is_open())sc.AddMessageToLog(messagee, 0);
  
  std::string date; // cant change these string's to SCString's because loop won't work
  std::string time;
  std::string value;
  std::string vvalue;
  
  for(int i = 1; i < 6; i++){
  
    std::getline(longs,date,',');
    std::getline(longs,time,',');
    std::getline(longs,value,',');
    std::getline(longs,vvalue,'\n');
    
    
    SCString date = date; // This doesn't work, i need to know how to make it a SCString
    SCString time = time; //
    SCString last = value;
    SCString volume = vvalue;
    
  
    // populates built in spreadsheet
    sc.SetSheetCellAsString(SheetHandle, 0, i, date); // I think the string has to be a SCString?
    sc.SetSheetCellAsString(SheetHandle, 1, i, time);
    sc.SetSheetCellAsString(SheetHandle, 2, i, value);
    sc.SetSheetCellAsString(SheetHandle, 3, i, vvalue);  
    }
    longs.close();

Output is blanks, the getline loop works,





cheers :-)
[2020-08-26 12:06:11]
User907968 - Posts: 802
You could use string::c_str function - https://www.cplusplus.com/reference/string/string/c_str/

Also, give the SCString objects different names to the std::string objects.


SCString sDate = date.c_str();

or

SCString sDate(date.c_str());

[2020-08-26 12:15:14]
User253985 - Posts: 21
Thank you so much, your response helped me a lot, much appreciated.

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

Login

Login Page - Create Account