Support Board
Date/Time: Mon, 10 Feb 2025 15:42:01 +0000
[Programming Help] - C++ std::string to SCString
View Count: 1728
[2020-08-26 11:25:44] |
User253985 - Posts: 23 |
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: 826 |
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: 23 |
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: