i 've an input file in .xls
my user wrote that in german excel version and so the floating point is like that 55,77
my c++ program can not read this number as i'm using an english c++ version
i did the conversion from , to . in the excel sheet and it works correctly, now i want that my c++ do that and the user do nothing.
there is a faunction in c++ that replace a certain char into another one from an input file!!!!!!!!!!!!!!!

Dani AI

Generated

Quick summary of the situation and practical options already floated here: has Excel data written with German formatting (decimal comma). suggested a simple text change, and pointed at switching the process locale. Both are valid, but there are safer, more robust ways to handle this from C++ depending on whether the file is a real Excel binary or a text export.

If the file is text (CSV/TSV), use C++ locale-aware parsing so the stream interprets the German decimal separator correctly. Imbuing a std::istringstream or std::ifstream with the appropriate std::locale lets extraction operators parse numbers without manual character hacks. Be aware that locale names differ between platforms and may throw if not installed, so fall back to a default and handle errors.

Example (conceptual):

#include <locale>
#include <sstream>
#include <string>

double parseNumber(const std::string& token) {
  std::istringstream in(token);
  try {
    in.imbue(std::locale("de_DE.UTF-8")); // platform-dependent
  } catch (...) {
    in.imbue(std::locale::classic());
  }
  double v;
  in >> v;
  if (!in) throw std::runtime_error("parse failed");
  return v;
}

If the input is an actual .xls binary, use a reader library rather than treating it as plain text. Libraries such as libxls parse Excel files and avoid brittle text assumptions.

Practical tips:

  • Detect input type first: binary .xls vs CSV.
  • If CSV, sniff a few lines to detect whether fields are semicolon-separated and whether numeric tokens contain comma or dot; choose an appropriate locale or parser.
  • Document the accepted format for users if you cannot rely on specific locales being available on the target machines.

References: std::locale and related facets on cppreference (std::locale, num_get). For binary Excel parsing see libxls (libxls on GitHub).

Recommended Answers

All 2 Replies

Member Avatar for Member #46692

>there is a faunction in c++ that replace a certain char into another one from an input file!!!!!!!!!!!!!!!

Just do something like:

Look for comma
  if found
    then change to full stop
  end if

What's the problem?

Assuming MS-Windows os, use SetLocal and the os will make the conversion for you when the values are read from the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.